【问题标题】:Could not find Controller method找不到控制器方法
【发布时间】:2014-04-10 05:26:19
【问题描述】:

在我的表单中,我有简单的更新表单,我可以从模型中填写输入标签。但是在点击提交按钮发送输入值后,我得到了这个错误:

Controller method not found. 

我的表格:

{{Form::model( array('route'=>array('admin.profile.update',$profile->id), 'method'=>'post')) }}

我的路线:

Route::group(array('prefix'=> 'admin' ,'before'=>'auth'), function(){
    Route::controller('profile', 'profileController', array('getIndex'=>'profile.index', 'postUpdate'=>'profile.update'));
});

我的控制器:

class ProfileController extends \BaseController {

    protected $layout = 'layouts.admin.main';

    function __construct() {
        $this->beforeFilter('auth', array('except' => array('getIndex', 'postUpdate')));
        $this->beforeFilter('csrf', array('on' => 'post'));
    }    
    public function getIndex()
    {

    }

    public function postUpdate($id)
    {

    }
}

html 的结果:

<form accept-charset="UTF-8" action="http://localhost/alachiq/admin/profile/index" method="POST"><input type="hidden" value="fDhe6m2qHh7NOERQaGvwDPJwCkbGTIRr56IBHseI" name="_token">

表单的动作是:

http://localhost/alachiq/admin/profile/index

那一定是:

http://localhost/alachiq/admin/profile/update

工匠路线:

GET admin/profile/index/{one?}/{two?}/{three?}/{four?}/{five?}   | profile.index  | profileController@getIndex 

GET admin/profile                                                |                | profileController@getIndex  

POST admin/profile/update/{one?}/{two?}/{three?}/{four?}/{five?} | profile.update | profileController@postUpdate 

【问题讨论】:

    标签: php laravel laravel-4


    【解决方案1】:

    您在此处放置了“命名路线”;

    {{Form::model( array('route'=>array('admin.profile.update',$profile->id), 'method'=>'post')) }}
    

    但是您的路线名称是“profile.update”(如您的工匠路线列表中所示) - 所以将其更改为

    {{Form::model( array('route'=>array('profile.update',$profile->id), 'method'=>'post')) }}
    

    编辑:我现在看到了问题。您已经完成了 Form::model() 而不是 Form::open(),但实际上还没有将模型传递给表单。要么你需要像这样传递你的模型:

    {{Form::model($model, array('route'=>array('profile.update',$profile->id), 'method'=>'post')) 
    

    或将您的表单更改为这样打开:

    {{Form::open( array('route'=>array('profile.update',$profile->id), 'method'=>'post')) 
    

    路线名称也可能存在问题,也可能仍然存在问题。

    【讨论】:

    • 那不正确,更改后出现错误
    猜你喜欢
    • 2014-04-29
    • 1970-01-01
    • 1970-01-01
    • 2023-01-27
    • 2015-10-09
    • 2016-04-04
    • 2014-03-09
    • 2014-05-12
    • 2014-01-04
    相关资源
    最近更新 更多