2014-02-18 44 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')); 
相關問題