LARAVEL的第一个控制器程序

来源:互联网 发布:台州市公务员网络学堂 编辑:程序博客网 时间:2024/04/28 02:12

将上一篇中的

Route::get('users', function(){    return 'Users!';});

修改成
Route::get('users', 'UserController@getIndex');
这样在地址栏中输入http://192.168.0.89:5605/users就会被控制器,

在app/controlers文件夹下建立一个UserController.php文件,然后在里边写入getIndex方法,这样就看到效果了

<?phpclass UserController extends BaseController {    /**     * Show the profile for the given user.     */    public function showProfile($id)    {        $user = User::find($id);        return View::make('user.profile', array('user' => $user));    }public function getIndex(){return "this is getIndex";}}?>
控制器应继承自basecontroller类。basecontroller也存储在app/controllers目录中,basecontroller扩展框架的控制器类。 


0 0