2014-02-09 59 views
0

我想要从form和ajax请求链接到控制器动作。我不能这样做。而我得到这个错误:Laravel链接到控制器动作

ErrorException 

Route [admin.profile.update] not defined. (View: /var/www/alachiq/app/views/back_end/layouts/profile.blade.php) 

我的形式profile.blade.php:

{{ Form::model($profile, array('action' => array('[email protected]', $profile->id), 'method' => 'PUT', 'id' => 'frm')) }} 

和Ajax请求转换成:

$.post("{{ route('admin.profile.update', $profile->id) }}", 

我的路线:

Route::controller('admin/profile', 'ProfileController', array('index'=>'profile.index','update'=>'profile.update')); 

我的控制器:

public function getIndex() 
{ 
    $profiles = Auth::user(); 
    return View::make('back_end.layouts.profile')->with('profile', $profiles); 
} 

public function postUpdate($id) 
{ 
    ... 
} 

回答

0

XHTML 1.x的形式仅支持GET和POST。 GET和POST是“method”属性唯一允许的值。 您是否有理由通过HTML表单发送PUT请求?

其次改变你的形式

echo Form::open(array('action' => '[email protected]','class' => '','id' => '')) 

路线

Route::controller('admin/profile', 'ProfileController'); 
+0

。我不khnow it.thanks。那么如何修复'$ .post(“<?php echo route('ProfileController @ postUpdate',$ profile-> id);?>”,' –

+0

提交ajax请求就像其他任何请求一样,你应该可以解析$ profile-> id作为一个隐藏的输入字段 $ .post(“admin/profile”,function(data){ // do something }); –

+0

thanks。i'change'$ .post'并把'$ profile-> id'作为隐藏的输入标签。witch name必须解析那个吗?''input type =“hidden”name ='id'value =“{{$ profile-> id}}”/>是'id:$('[name = id]')。val(),'currect? –