2014-02-18 45 views
1

我有困难得到这个工作正常,可能有一个错误的方式,我想通过ID变量的方法。我正在使用Laravel。错误在PHP中:从空值创建默认对象

我的观点包含这种形式来处理函数并传递ID:

{{ Form::open(array('method' => 'GET', 'url' => array('uploads/edit', $upload->id))) }} 
    {{ Form::submit('Edit', array('class' => 'btn btn-info')) }} 
{{ Form::close() }} 

控制器:

public function getEdit($id) 
{ 
    $upload = $this->upload->find($id); 

    if (is_null($upload)) 
    { 
    return Redirect::to('uploads/alluploads'); 
    } 

    $layout->layout->content = View::make('uploads.edit', compact('upload')); 
} 

错误:

ErrorException 
Creating default object from empty value 

回答

3

的错误就在这里;

$layout->layout->content = .... 

你不能这样做,因为你没有定义$ layout,或$ layout-> layout。尝试:

$layout = View::make('uploads.edit', compact('upload')); 

或者如果您真的热衷于让它完全像您的代码一样,那么您可以这样做;

$layout = new stdClass(); 
$layout->layout = new stdClass(); 

$layout->layout->content = View::make('uploads.edit', compact('upload')); 
相关问题