在非对象Laravel 4.2上调用成员函数where() [英] Call to a member function where() on a non-object Laravel 4.2

查看:78
本文介绍了在非对象Laravel 4.2上调用成员函数where()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am attempting to use and id that being passed into the URL to edit the query but when attempting to run the code I get an error of:

在非对象上调用成员函数where()

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);
    }

}

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

Only to be thrown the same error message and this is the only snippet that has not thrown the error but returns with a error of:

mysql_fetch_array()期望参数1为资源,给定对象

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'
    ));

推荐答案

我试图将std Obj数组传递给视图,但是我必须设置wab_id,因为如果没有,我接下来将得到wab_id的未定义索引 $arrays = json_decode(json_encode($results), true);为了将使用查询获取的std数组转换为多数组,然后遍历该数组,并且有效

i was trying to pass an std Obj array to the view, but i had to set wab_id because if not i would get a undefined index of wab_id next i $arrays = json_decode(json_encode($results), true); in order to get the std array that i was getting with using the query into a multi array then looped through the array and that worked

感谢大家的帮助.

控制器

class HomeController extends BaseController {

        public function showWelcome(){
            $id = isset($_GET['wab_id'])?$_GET['wab_id']:"";

            $results = DB::Table('films')->where('wab_id', $id)->get();

            $arrays = json_decode(json_encode($results), true);

            foreach ( $arrays as $film ) {

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

        }

    }

这篇关于在非对象Laravel 4.2上调用成员函数where()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆