laravel控制器

 1、怎么新建一个控制器
        例子(1)
            新建一个控制器类:
            app/Http/Controllers/MemberController.php
                namespace App\Http\Controllers;
                class MemberController extends Controller {
                    public function index() {
                        return route('member');
                    }
                }
            
            添加路由:
            app/Http/routes.php    
                Route::get('member/index', [
                    'uses' => 'MemberController@index',
                    'as'   => 'member'
                ]);

        例子(2)传递参数、验证参数
            namespace App\Http\Controllers;
            class MemberController extends Controller {
                public function index($id) {
                    return $id;
                }
            }

            Route::get('member/{id}', [
                'uses' => 'MemberController@index',
                'as'   => 'member'
            ])->where('id', '[0-9]+');

    2、分配数据
        return view('phpknowledge.index', [
            'all_knowledge' => $all_knowledge
        ]);

 

posted @ 2017-06-02 13:34  刘小伟  阅读(141)  评论(0编辑  收藏  举报