LoginSignup
18
14

More than 5 years have passed since last update.

CakePHPのルーティング設定について

Last updated at Posted at 2014-08-08

CakePHPではコントローラ/アクションに紐づけるURLを手動で設定する事が出来る機能が
あります。それが「*Router::connect」です。

使い方は次の通り

1. app/Config/routes.phpを開く
2. 下記を入力する(入力はサンプルです。)

//第1引数は「CakePHPは任意に指定したいURL」
//第2引数はURLに紐づけるコントローラです。
Router::connect('/user/login', array(
    'controller' => 'myLogin', 
    'action' =>'index'
));

3. 保存する

でOKです。

サンプルで指定したルーティング設定はどういう事かというと、

URL「 http://{CakePHPのルート}/user/login 」 は,

* コントローラ: MyLoginController
* アクション: index

にアクセスしますよ!

という事です。

ちなみにルーティング設定を設定していると,ビューのヘルパーで

$this->Html->link(array(
    'controller' => 'myLogin', 
    'action' =>'index'
));

と指定すると指定したルーティング設定で設定したURLでaタグを生成してくれます。

18
14
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
18
14