cakePHPのバージョン2.5を使ってroutes.phpを使いルーティングを設定をしようと思っています。
下記のようにroutes.phpを記載していますが、routes.phpに記載した通りにルーティングせず、
cakePHPに初期のURLでしかアクセスできない状況です。
http://hoge.jp/tests/add
を
http://hoge.jp/test/
のようにしたいと思っています。
記載しているroutes.phpは下記のような内容です。
php
1<?php 2/** 3 * Routes configuration 4 * 5 * In this file, you set up routes to your controllers and their actions. 6 * Routes are very important mechanism that allows you to freely connect 7 * different URLs to chosen controllers and their actions (functions). 8 * 9 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) 10 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) 11 * 12 * Licensed under The MIT License 13 * For full copyright and license information, please see the LICENSE.txt 14 * Redistributions of files must retain the above copyright notice. 15 * 16 * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) 17 * @link http://cakephp.org CakePHP(tm) Project 18 * @package app.Config 19 * @since CakePHP(tm) v 0.2.9 20 * @license http://www.opensource.org/licenses/mit-license.php MIT License 21 */ 22/** 23 * Here, we are connecting '/' (base path) to controller called 'Pages', 24 * its action called 'display', and we pass a param to select the view file 25 * to use (in this case, /app/View/Pages/home.ctp)... 26 */ 27// Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); 28/** 29 * ...and connect the rest of 'Pages' controller's URLs. 30 */ 31// Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); 32 33 Router::connect('/', array('controller' => 'tests', 'action' => 'index')); 34 Router::connect('/test/', array('controller' => 'tests', 'action' => 'add')); 35 36/** 37 * Load all plugin routes. See the CakePlugin documentation on 38 * how to customize the loading of plugin routes. 39 */ 40 CakePlugin::routes(); 41 42/** 43 * Load the CakePHP default routes. Only remove this if you do not want to use 44 * the built-in default routes. 45 */ 46 require CAKE . 'Config' . DS . 'routes.php'; 47
詳細としては、
php
1Router::connect('/', array('controller' => 'tests', 'action' => 'index')); 2Router::connect('/test/', array('controller' => 'tests', 'action' => 'add'));
Router::connect('/', array('controller' => 'tests', 'action' => 'index'));
は、ルーティングされるのですが、
Router::connect('/test/', array('controller' => 'tests', 'action' => 'add'));
が、ルーティングされない状況です。
よろしくお願い致しいます。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。