19
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CakePHPでController, Model, Viewで階層を深くするための設定

Posted at

概要

Controllerの数が増えてきて、何らかの区分でディレクトリを分けたい場合の設定を書きます。

実装

bootstrap.phpに以下の記述をすることで実現可能です。
例として以下のケースを想定したコードを記します。
ex ) admin用のcontrollerはadminディレクトリにまとめたい

bootstrap.php
App::build(array(
    'Controller' => array(
        ROOT.DS.APP_DIR.DS.'Controller'.DS,
        ROOT.DS.APP_DIR.DS.'Controller'.DS.'Admin'.DS,
    )
));

これでControllerの階層を実現することができます。
これは同様にModel, Viewでも実現でき、すべてやるとしたら以下のようになります。

bootstrap.php
App::build(array(
    'Controller' => array(
        ROOT.DS.APP_DIR.DS.'Controller'.DS,
        ROOT.DS.APP_DIR.DS.'Controller'.DS.'Admin'.DS,
    ),
    'Model' => array(
        ROOT.DS.APP_DIR.DS.'Model'.DS,
        ROOT.DS.APP_DIR.DS.'Model'.DS.'Admin'.DS,
    ),
    'View' => array(
        ROOT.DS.APP_DIR.DS.'View'.DS,
        ROOT.DS.APP_DIR.DS.'View'.DS.'Admin'.DS,
    ),
));

参考

19
20
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
19
20

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?