更新laravel 4.2中的记录


updating of records in laravel 4.2

你好,我是laravel 4.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()}}

我不知道如何使窗体调用函数public function c_updateSystemUser($id)在我的控制器

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

任何想法?如有任何帮助,不胜感激

如果你的视图名称是update并且它在views->csu文件夹中,你可以像下面这样做

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

你的路由应该像这样:

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

systemUsers.php中加入c_updateSystemUser($id){}