gpt4 book ai didi

mysql - Laravel 4 - 找不到 Controller

转载 作者:太空宇宙 更新时间:2023-11-03 10:54:23 26 4
gpt4 key购买 nike

我正在使用 laravel 开发一个应用程序,它将文件保存在数据库和目标文件夹中。我试图从数据库中删除一条记录,但我得到的只是一个错误,表明找不到 Controller 方法。

错误:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Controller method not found.

throw new NotFoundHttpException("Controller method not found.");

View alluploads.blade.php 有一个表单,它应该将 id 传递给上传/销毁函数。

{{ Form::open(array('method' => 'DELETE', 'url' => array('uploads/destroy', $upload->id))) }}
{{ Form::submit('Delete', array('class' => 'btn btn-danger')) }}
{{ Form::close() }}

我的 Controller 有删除行的功能。

public function getDestroy($id)
{
$this->upload->find($id)->delete();
return Redirect::to('uploads/alluploads')->with('message', 'Thanks, delete was successful!');
}

路由具有以下访问上传 Controller 下的功能

Route::controller('uploads', 'UploadsController');

最佳答案

您正在使用 HTTP 方法 DELETE,因此您的 Controller 方法应该是:

public function deleteDestroy($id)
{
$this->upload->find($id)->delete();
return Redirect::to('uploads/alluploads')->with('message', 'Thanks, delete was successful!');
}

看看你的路线:

php artisan routes

至少,你必须在那里看到这样的东西:

+--------+---------------------------------------------------------------+----------------------+-------------------------------------------------------+--------------------------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+---------------------------------------------------------------+----------------------+-------------------------------------------------------+--------------------------------+---------------+
| | DELETE uploads/destroy/{one?}/{two?}/{three?}/{four?}/{five?} | | UploadsController@deleteDestroy | | |
| | GET uploads/{_missing} | | UploadsController@missingMethod | | |
+--------+---------------------------------------------------------------+----------------------+-------------------------------------------------------+--------------------------------+---------------+

要按照表单打开行的方式使用您的表单,必须是:

Form::open(array('method' => 'GET', 'url' => array('uploads/destroy', $upload->id)))

但我认为现在的方式更好,只需重命名您的方法即可。

关于mysql - Laravel 4 - 找不到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21855767/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com