【发布时间】:2014-03-15 01:14:05
【问题描述】:
我正在使用Route::controller 查看和编辑表单。在这个动作中 laravel 说:
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
Controller method not found.
我的路线:
Route::group(array('prefix'=> 'admin' ,'before'=>'auth'), function(){
Route::controller('profile', 'ProfileController', array('getIndex'=>'profile.index', 'postUpdate'=>'profile.update'));
});
我的表格:
{{ Form::model($profile, array('route' => array('profile.update', $profile->id), 'method' => 'PUT')) }}
{{ Form::close() }}
配置文件控制器:
class ProfileController extends \BaseController {
public $layout = 'back_end.layouts.main';
function __construct() {
$this->beforeFilter('auth', array('except' => array('getIndex', 'postUpdate')));
$this->beforeFilter('csrf', array('on' => 'post'));
}
public function getIndex()
{
if( Auth::check() ){
$profiles = Auth::user();
return View::make('back_end.layouts.profile')->with('profile', $profiles);
}
else return Redirect::intended('login');
}
public function postUpdate($id)
{
if (Session::token() != Input::get('_token'))
{
return Response::view('back_end.missing', array(), 404);
}
$rules = array(
'name' => 'required|alpha',
'family' => 'required',
'email' => 'required|email',
'currPassword'=> 'required',
'password' => 'required|confirmed',
'password_confirmation'=>'required',
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
return Redirect::to('/admin/profile')
->withErrors($validator)
->withInput();
}
$id = Input::get ('id');
$data = User ::find($id);
$HashPassowrd = Hash::make(Input::get('password'));
if( ! Hash::check( Input::get('currPassword') , $data->password ) )
{
return Redirect::to('/admin/profile')
->withErrors('Current Password Error!');
}
else{
$admin = new User;
$admin = User::find($id);
$admin->name = Input::get('name');
$admin->family = Input::get('family');
$admin->email = Input::get('email');
$admin->password = $HashPassowrd;
$admin->save();
return Redirect::to('/admin/profile')
->withErrors('Edit Successfull');
}
}
}
php 工匠路线
+--------+------------------------------------------------------------------------+---------------------+---------------------------------------+----------------+---------------+
| Domain | URI | Name | Action | Before Filters | After Filters |
+--------+------------------------------------------------------------------------+---------------------+---------------------------------------+----------------+---------------+
| | GET / | | Closure | | |
| | GET index | index | Closure | | |
| | GET admin/index | dashboard | Closure | | |
| | GET logout | logout | Closure | | |
| | POST auth | auth | Closure | csrf | |
| | GET login | login | Closure | | |
| | GET admin/profile/index/{one?}/{two?}/{three?}/{four?}/{five?} | profile.index | ProfileController@getIndex | auth | |
| | GET admin/profile | | ProfileController@getIndex | auth | |
| | POST admin/profile/update/{one?}/{two?}/{three?}/{four?}/{five?} | profile.update | ProfileController@postUpdate | auth | |
| | GET admin/profile/{_missing} | | ProfileController@missingMethod | auth | |
| | GET admin/manaheHeaders/index/{one?}/{two?}/{three?}/{four?}/{five?} | manageHeader.index | ManageHeadersController@getIndex | auth | |
| | GET admin/manaheHeaders | | ManageHeadersController@getIndex | auth | |
| | POST admin/manaheHeaders/update/{one?}/{two?}/{three?}/{four?}/{five?} | manageHeader.update | ManageHeadersController@postUpdate | auth | |
| | GET admin/manaheHeaders/{_missing} | | ManageHeadersController@missingMethod | auth | |
| | GET test | test | Closure | | |
+--------+------------------------------------------------------------------------+---------------------+---------------------------------------+----------------+---------------+
【问题讨论】:
-
也许检查
artisan routes的输出以确保您的URI 和路由名称是正确的。此外,您没有提到(或者我没有看到)错误出现的确切位置 - 是在调用Form::open()期间,还是在浏览器中访问 URI(或两者)?如果Form::open()调用正常并显示表单,则可能值得检查它生成的 URL,以确保符合您对路由的期望。 -
你点击的网址是什么?
-
@AntonioCarlosRibeiro 在路由或控制器中?
-
网址 =
http://box.dev/what/url/are/you/hitting? -
这是在你发送表单时发生的,还是在 Laravel 试图渲染表单时发生的?通过其他 cmets,看起来表单正在呈现,至少您有一个 URL...只是想确定当您单击按钮发布表单时是否正在发生...