有什麼區別:類的名稱作爲一個公共函數參數
class PostController extends \BaseController {
public function delete($id) {
$deletePost = Post::findOrFail($id);
return View::make('backend.delete')->with('post', $deletePost);
}
}
和
class PostController extends \BaseController {
public function delete(Post $post) {
return View::make('backend.delete')->with('post', $post);
}
}
誰能給我解釋一下:public function delete(Post $post)
我們採取了一個名爲「郵報班「作爲變量$post
?
UPDATE1。
在routes.php文件:
Route::model('post', 'Post');
Route::get('delete/{post}', array('uses' => '[email protected]'));
Route::post('delete', array('uses' => '[email protected]'));
和PostController.php:
public function delete(Post $post) {
return View::make('backend.delete')->with('post', $post);
}
public function doDelete() {
$post = Post::findOrFail(Input::get('id'));
$post->delete();
return Redirect::action('[email protected]');
}
但無論如何,我得到一個錯誤:沒有找到模型[發佈]查詢結果。 用第二種方法。
不,作爲$ post傳遞的參數必須是'Post'類型的對象實例,或者是擴展'Post' –
http://docs.php.net/manual/en/language.oop5的類的對象實例。 typehinting.php – Deadooshka