laravel 试图获取非对象的属性
Posted
技术标签:
【中文标题】laravel 试图获取非对象的属性【英文标题】:laravel trying to get property of non object 【发布时间】:2015-09-22 23:51:42 【问题描述】:我在 laravel 4.2 中遇到错误 “试图获取非对象的属性”
以前很好用,现在不知道为什么。
这是我的代码:
控制器:
public function id($lang,$id,$vers)
// $Agent = new Agent();
// if ($Agent->isMobile())
// $data['settings'] = Courses::settings($id, $vers);
// $this->layout->content = View::make('gui.mobile')->with('data', $data);
// else
$data['index'] = Courses::productsIndex($id);
$data['langs'] = Courses::langsclient($id);
$data['settings'] = Courses::settings($id, $vers);
$this->layout->content = View::make('gui.home')->with('data', $data);
//
型号:
public static function productsIndex($id,$html='')
$clients = DB::table('clients')->where('client_id',$id)->first();
$clients_settings = DB::table('clients_settings')->where('clients_id',$id)->first();
$courss = explode(',', $clients->products);
$IndexCats = '';
$IndexCats .= '<a href="#all" title="">' . trans('home.All Products') .'</a>';
foreach($courss as $index)
$IndexCats .= '<a href="#' . $index . '" title="" rel="' . $index . '">' . trans('home.' . $index) . '</a>';
$clients = DB::table('clients')->where('client_id',$id)->first();
$cours = explode(',', $clients->coruses);
$tabs ='';
$links='';
foreach($cours as $row)
$idcours = DB::table('courses')->where('id',$row)->get();
$coursCount = DB::table('lessons')->where('courses_id',$row)->count();
$clients_settings = DB::table('clients_settings')->where('clients_id',$id)->first();
$clients_images_ebook = DB::table('mediameneger')->where('name','ebook')->where('type','image')->where('client_id',$id)->first();
if($row == 'ebook')
$image_ebook = !empty($clients_images_ebook->fullpath) ? $clients_images_ebook->fullpath : url() .'/files/images/ebook.jpg';
$tabs .= '<li class="videos ebook" style="background-image: url(' . $image_ebook . '?86400' .');">';
$tabs .= '<p><a href="'. url() .'/gui/' . Request::segment(2) . '/'. $id .'/' . Request::segment(4) . '/ebooks">Ebook';
$tabs .= '<span class="more"><br />';
$tabs .= '<i class="hidden-xs cercale glyphicon glyphicon-book fa-3x"></i></span>';
$tabs .= '</a></p>';
$tabs .= '</li>';
if($row == 'ebook_forex')
$image_ebook = !empty($clients_images_ebook->fullpath) ? $clients_images_ebook->fullpath : url() .'/files/images/ebook.jpg';
$tabs .= '<li class="videos ebook" style="background-image: url(' . $image_ebook . '?86400'.');">';
$tabs .= '<p><a href="'. url() .'/gui/' . Request::segment(2) . '/'. $id .'/' . Request::segment(4) . '/ebooks_forex">Ebook Forex';
$tabs .= '<span class="more"><br />';
$tabs .= '<i class="hidden-xs cercale glyphicon glyphicon-book fa-3x"></i></span>';
$tabs .= '</a></p>';
$tabs .= '</li>';
if($row == 'chats')
$image_ebook = !empty($clients_images_ebook->fullpath) ? $clients_images_ebook->fullpath : url() .'/files/images/chat.jpg';
$tabs .= '<li class="videos chats" style="background-image: url(' . $image_ebook . '?86400'.');">';
$tabs .= '<p><a href="'. url() .'/gui/' . Request::segment(2) . '/'. $id .'/' . Request::segment(4) . '/chats">Chat with an expert';
$tabs .= '<span class="more"><br />';
$tabs .= '<i class="hidden-xs cercale fa fa-weixin fa-3x"></i></span>';
$tabs .= '</a></p>';
$tabs .= '</li>';
foreach($idcours as $row2)
$lang = !empty(Session::get('local')) ? Session::get('local') : 'gb';
$showbox = DB::table('mediameneger')->where('course',$row2->id)->where('lang', $lang)->limit(1)->get();
$clients_images = DB::table('mediameneger')->where('course',$row2->id)->where('type','image')->where('client_id',$id)->first();
foreach ($showbox as $key)
$lang = Session::get('local') != null ? Session::get('local') : Request::segment(2);
$image = !empty($clients_images->fullpath) ? $clients_images->fullpath : $row2->imagepath;
$tabs .= '<li class="videos" style="background-image: url('. $image . '?86400' .');">';
$tabs .= '<p><a href="'. url() .'/gui/' . $lang . '/' . $id .'/' . Request::segment(4) . '/lessons/' . $row2->id . '">' . trans('home.'. $row2->name . '') . '';
$tabs .= '<span class="more"><i class="text">' . $coursCount . ' ' . trans('home.lessonstotal') .'</i><br />';
$tabs .= '<i class="hidden-xs cercale glyphicon glyphicon-play fa-3x"></i></span>';
$tabs .= '</a></p>';
$tabs .= '</li>';
$tabs .='<li style="overflow: hidden; clear: both; height: 0; position: relative; float: none; display: block;"></li>';
$data['tabs'] = $tabs;
$data['IndexCats'] = $IndexCats;
return $data;
错误来自所有的explode(); 而且我不知道为什么以前工作。
【问题讨论】:
尝试转储 $clients 变量的值,显然它是空的clients
表中是否存在client_id
等于$id
值的记录?
你在哪一行得到这个错误?
我在 exploade() 中得到了错误。我打印 $client 并得到值。
【参考方案1】:
退出您的网站,然后重新登录。这通常会在您暂时不使用本地开发服务器时发生。
【讨论】:
【参考方案2】:尝试运行命令“php artisan dump-autoload”和composer“dump-autoload”。
【讨论】:
我如何在我的服务器上做到这一点? SSH?以上是关于laravel 试图获取非对象的属性的主要内容,如果未能解决你的问题,请参考以下文章