LoginSignup
0
0

More than 5 years have passed since last update.

fuelphp1.8 routerメソッドをつかってURLを動的にする

Last updated at Posted at 2018-06-06

DBに登録したショップデータを表示するコントローラーで、actionの引数でなく、メソッド部分を動的にして表示する

通常
http://example.jp/コントローラ/メソッド/(ショップID)/

したい事
http://example.jp/コントローラ/(ショップID)/

controller_shop.php
    public function router($method, $params){

        $shop = Model_Shop::query()->where('shop_id','=',$method)->get_one();

        if($shop){
            //DB登録されているショップデータの要求があった場合.
            return $this->view($shop);
        }else if(method_exists($this,'action_'.$method)){
            //actionメソッドでの要求があった場合.
            return $this->{'action_'.$method}($params);
        }else{
            //ページが存在しないURLの場合.
            return Request::forge('_404_')->execute();
        }

    }
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0