Php 仅在Live Server上存在未定义的变量错误Laravel
我正在做一个定制的Laravel项目 我遇到以下错误:Php 仅在Live Server上存在未定义的变量错误Laravel,php,laravel,Php,Laravel,我正在做一个定制的Laravel项目 我遇到以下错误: Undefined variable: count_pandding (View: /domains/web4/html/manager/app/views/admin/home.blade.php) 但奇怪的是,这个错误并没有显示在localhost中,并且只在life server中才能完美地工作 我尝试过用两种方式传递变量: public function home() { $count_pandding = \Postj
Undefined variable: count_pandding (View: /domains/web4/html/manager/app/views/admin/home.blade.php)
但奇怪的是,这个错误并没有显示在localhost中,并且只在life server中才能完美地工作
我尝试过用两种方式传递变量:
public function home()
{
$count_pandding = \Postjob::where('approve',0)->get()->count();
$count_disapprove = \Postjob::where('approve',2)->get()->count();
$count_approve = \Postjob::where('approve',1)->get()->count();
$count_expire = \Postjob::where('approve',3)->get()->count();
return View::make('admin.home', compact('count_pandding','count_disapprove','count_approve','count_expire'));
}
第二条路
public function home()
{
$data['count_pandding'] = \Postjob::where('approve',0)->get()->count();
$data['count_disapprove'] = \Postjob::where('approve',2)->get()->count();
$data['count_approve'] = \Postjob::where('approve',1)->get()->count();
$data['count_expire'] = \Postjob::where('approve',3)->get()->count();
return View::make('admin.home',$data);
}
所有这些在Life Server中都不起作用!但是在本地主机上工作得非常好。请查看
make的第二个参数是带有键值绑定的数组。我觉得奇怪,这是在你的本地机器上工作
试一试
更新:
return View::make('admin.home')->with($keyValueArray);
//should also translate into $key inside the view.
返回视图::make'admin.home',['count\u pandding'=>$count\u pandding,'count\u unapprove'=>$count\u unapprove,'count\u approve'=>$count\u expire];在本地主机而非实时服务器中工作。我甚至尝试过创建$data数组并使用make传递,returnview::make'admin.home'->withCountPannding$count\u pannding;工作,但如何传递所有数据?真的很奇怪,你的本地php版本与服务器的php版本是什么?本地:5.5.12/Server:5.4.16这是唯一一个没有找到的变量,如果是,请检查拼写。PHP版本应该是正常的,检查我的更新答案它无法找到所有的变量。
return View::make('admin.home')->with($keyValueArray);
//should also translate into $key inside the view.