编程语言
首页 > 编程语言> > php-在非对象Laravel 4.2上调用成员函数where()

php-在非对象Laravel 4.2上调用成员函数where()

作者:互联网

我正在尝试使用传递给URL的id和id来编辑查询,但是在尝试运行代码时出现以下错误:

Call to a member function where() on a non-object

控制者

class HomeController extends BaseController {

    public function showWelcome() {
        $id = intval($_GET['wab_id']);
        $results = DB::Table('films')->get()->where('wab_id','=', $id);
        print_r($results);
        while ($row=mysql_fetch_array($results)) {       
            $url = $row['url'];

        } 
         return View::make('hello')->with('row', $url);
    }

}

我也尝试过:

class HomeController extends BaseController {

    public function showWelcome() {
        $id = intval($_GET['wab_id']);
        $results = DB::Table('films')->get()->where('wab_id', $id);
        print_r($results);
        while ($row=mysql_fetch_array($results)) {       
            $url = $row['url'];

        } 
         return View::make('hello')->with('row', $url);
    }

}

仅引发相同的错误消息,这是唯一未引发错误但返回错误为的代码段:

mysql_fetch_array() expects parameter 1 to be resource, object given

class HomeController extends BaseController {

    public function showWelcome() {
        $id = intval($_GET['wab_id']);
        $results = DB::Table("SELECT * FROM next WHERE wab_id=$id");
        while ($row=mysql_fetch_array($results)) {       
            $url = $row['url'];

        } 
         return View::make('hello')->with('row', $url);
    }

}

路线

Route::get('/', array(
    'as' => 'home',
    'uses' => 'HomeController@showWelcome'
    ));

解决方法:

您需要更改链接的顺序,以将where()函数放在get()函数之前. get()之后的所有内容都将应用于集合,而不是查询构建器.

标签:laravel-routing,model-view-controller,laravel-4,php
来源: https://codeday.me/bug/20191120/2046024.html