Php 更新laravel 4.2中的记录

Php 更新laravel 4.2中的记录,php,laravel-4,laravel-routing,Php,Laravel 4,Laravel Routing,您好,我是Laravel4.2的新手,我正在控制器中制作一个应用程序,我制作了自己的函数c_updateSystemUser($id),下面是代码 public function c_updateSystemUser($id) { // session_start(); $getsCapt = $_SESSION["captcha"]; $rules = array( 'username' => 'required|min:2|m

您好,我是Laravel4.2的新手,我正在控制器中制作一个应用程序,我制作了自己的函数c_updateSystemUser($id),下面是代码

public function c_updateSystemUser($id)
{
    //
    session_start();
    $getsCapt = $_SESSION["captcha"];


    $rules = array(
        'username'     => 'required|min:2|max:50|regex:/^[a-zA-Z0-9\-\s]+$/|exists:dbo_systemusers,SystemUserName,$id',
        'description'  => 'required|min:1|max:100|regex:/^[a-zA-Z0-9\-\s]+$/',
        'usertype'     => 'required|numeric',
        'capt'         => 'required|numeric'
    );

    $validator = Validator::make(Input::all(), $rules);
    // process the inputs given by the user
    if ($validator->fails()) 
    {
        return Redirect::to('viewsu/' . $id)
            ->withErrors($validator)
            ->withInput(Input::except('password'));
    } 
    else 
    {

            // store the values into the database
            $su = SystUser::find($id);
            $su->SystemUserTypeID       = Input::get('usertype');
            $su->SystemUserName         = Input::get('username');
            $su->SystemUserDescription  = Input::get('description');
            $su->timestamps = false;
            $su->save();

            Session::flash('message', 'Successfully created system user!');
            return Redirect::to('viewsu');
        }
    }
}
我希望在用户单击我的视图文件上的更新按钮时调用此函数,但当单击按钮时,它将重定向到其他页面(我的创建用户页面),我不知道为什么 这是我刀片上的表格代码

 {{ Form::model($su, array('route' =>array('csu.update',$su->SystemUserID),'method'=>'PUT'))}}

            <div class="form-group">
                {{ Form::label('usertype', 'User Type') }}
                {{ Form::select('usertype', [null=>'Please Select user type'] + $sTyp , array('class'=>'form-control'))}}
                {{ Form::label('current' , 'Current Type: (unedited) '.$su->SystemType , array('class' => 'label label-primary')) }}
            </div>

            <div class="form-group">
                {{ Form::label('username', 'Username') }}
                {{ Form::text('username', $su->SystemUserName, array('class' => 'form-control')) }}
            </div>

            <div class="form-group">
                {{ Form::label('description', 'Description') }}
                {{ Form::textarea('description', $su->SystemUserDescription, array('class' => 'form-control','rows' => '3')) }}
            </div>
             <div class="form-group">
                {{ Form::label('captcha', 'CAPTCHA image: ') }}
                </br>

                {{ HTML::image('http://localhost:8080/laravel3/app/captcha.php', 'alt' , array( 'width' => 200, 'height' => 35 )) }} </br></br>
                {{ Form::text('capt', Input::old('capt'), array('class' => 'form-control','placeholder' => 'enter generated captcha')) }}
            </div>

            {{ Form::submit('Edit System User', array('class' => 'btn btn-primary')) }}

{{ Form::close()}}
{{Form::model($su,array('route'=>array('csu.update',$su->SystemUserID),'method'=>'PUT'))}
{{Form::label('usertype','User Type')}
{{Form::select('usertype',[null=>'请选择用户类型']+$sTyp,数组('class'=>'Form-control'))}
{{Form::label('current','current Type:(未编辑).$su->SystemType,array('class'=>'label-label-primary'))}
{{Form::label('username','username')}
{{Form::text('username',$su->SystemUserName,array('class'=>'Form control'))}
{{Form::label('description','description')}
{Form::textarea('description',$su->SystemUserDescription,array('class'=>'Form control','rows'=>'3'))}
{{Form::label('captcha','captcha image:')}

{{HTML::image('http://localhost:8080/laravel3/app/captcha.php“,”alt',数组('width'=>200,'height'=>35))}

{{Form::text('capt',Input::old('capt'),array('class'=>'Form control','placeholder'=>'enter generated captcha'))} {{表单::提交('Edit System User',array('class'=>'btn btn primary'))} {{Form::close()}}
我不知道如何使窗体调用我的控制器中的函数
公共函数c_updateSystemUser($id)

我的控制器文件名为systemUsers.php


有什么想法吗?如果您的视图名为update,并且它位于
视图->csu
文件夹中,您可以像下面这样做,我们将非常感谢您的帮助

{{ Form::model($su, array('route' =>array('csu.update.c_updateSystemUser',$su->SystemUserID),'method'=>'PUT'))}}
 #yourentry
{{Form::close()}}
您的路线应如下所示:

    Route::resource('csu','systemUsers');

systemUsers.php
add
c\u updateSystemUser($id){}
method.

你能发布你的路线吗?
Route::resource('csu','systemUsers@c_storeSU'); 路由::get('createsu','systemUsers@c_createSystemUser'); 路由::get('viewsu','systemUsers@c_viewSystemUser'); 路由::get('viewsu/{id}',array('as'=>'findSU','uses'=>'systemUsers@c_editSystemUser'));这是我使用的路由您没有处理put请求的路由吗?您可能需要如下内容:route::put('/doesntmatter',array('as'=>'csu.update','uses'=>'myController@c_updateSystemUser'));另外,如果我是你的老板并且认识拉威尔。。。我不会接受的。使用laravels文档和PSR标准提供的命名约定。e、 g无c_更新系统管理员。。。而是创建一个用户控制器,然后使用一个用户绑定到传递的参数的update(user$user)方法。您还可以使用表单请求验证: