2014-01-16 58 views
1

我想在我的CakePHP應用程序中創建一個靜態的/terms頁面。我有一個app/View/Pagesterms.ctp以下的app/Config/routes.phpCakephp路由 - 丟失控制器

<?php 
/** 
* Routes configuration 
* 
* In this file, you set up routes to your controllers and their actions. 
* Routes are very important mechanism that allows you to freely connect 
* different URLs to chosen controllers and their actions (functions). 
* 
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) 
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) 
* 
* Licensed under The MIT License 
* For full copyright and license information, please see the LICENSE.txt 
* Redistributions of files must retain the above copyright notice. 
* 
* @copyright  Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) 
* @link   http://cakephp.org CakePHP(tm) Project 
* @package  app.Config 
* @since   CakePHP(tm) v 0.2.9 
* @license  http://www.opensource.org/licenses/mit-license.php MIT License 
*/ 
/** 
* Here, we are connecting '/' (base path) to controller called 'Pages', 
* its action called 'display', and we pass a param to select the view file 
* to use (in this case, /app/View/Pages/home.ctp)... 
*/ 
    Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); 
/** 
* ...and connect the rest of 'Pages' controller's URLs. 
*/ 
    Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); 

/** 
* Load all plugin routes. See the CakePlugin documentation on 
* how to customize the loading of plugin routes. 
*/ 
    CakePlugin::routes(); 

/** 
* Load the CakePHP default routes. Only remove this if you do not want to use 
* the built-in default routes. 
*/ 
    require CAKE . 'Config' . DS . 'routes.php'; 

    Router::connect('/terms', array('controller' => 'pages', 'action' => 'display', 'terms')); 

但是參觀http://cakeapp.com/terms我得到一個丟失的控制器錯誤時:

Error: TermsController could not be found.

任何想法?

+0

'http://cakeapp.com/術語/'作品? –

+0

不,我得到一個神祕的丟失的控制器錯誤 – dcd0181

回答

6

移動的路線了:(主叫CakePlugin::routes();前),否則,這條線路將被忽略

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); 
/** 
* ...and connect the rest of 'Pages' controller's URLs. 
*/ 
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); 

Router::connect('/terms/', array('controller' => 'pages', 'action' => 'display', 'terms')); 
+0

是的,自定義路由必須事先'需要CAKE。 '配置'。 DS。 'routes.php';'放置catch-all路徑'/:controller /:action/*'。 –

+0

手掌/臉...只是有一個時刻。這工作通過省略尾隨「/」。謝謝! – dcd0181

3

嘗試刪除結束斜線:

Router::connect(
    '/terms', 
    array(
     'controller' => 'pages', 
     'action' => 'display', 'terms' 
    ) 
); 
+0

仍然丟失控制器,只是添加了其餘的routes.php,我不知道發生了什麼 – dcd0181