2016年4月8日金曜日

cakephp3 管理画面 ディレクトリ構成変更

PHP Ver 5.6.27
CakePHP Ver 3.1.9



cakephp3 ディレクトリ構成 変更


設定

・config/routes.php
Router::prefix('{prefixName}', function ($routes) {
    $routes->fallbacks('DashedRoute');
});

Router::scope('/{prefixName}', function ($routes) {
    $routes->connect('/', ['controller' => '{controllerName}', 'action' => '{actionName}', 'prefix' => '{prefixName}']);
});


この設定をすることで、URL: http://example.com/{prefixName} で内部的には
src/Controller/{prefixName}/{ControllerName}.php {actionName} メソッドにアクセスしてくれる。

その他の画面用 Controller も src/Controller/{prefixName}/ 配下に作成し、

$this->Html->link(__('View'), ['controller' => '{anotherControllerName}', 'action' => '{anotherActionName}']])

と記述すれば、自動的に http://example.com/{prefixName}/{anotherControllerName}/{anotherActionName} にアクセスしてくれる

0 件のコメント:

コメントを投稿