我已将我的应用设置为“图书索引页”
这是我的地址
http://myapp.loc/
这是路由器
Router::connect('/', array('controller' => 'books', 'action' => 'index'));
当我转到http://myapp.loc/
时,页面加载就好了。但是当我点击该页面中的一个链接(假设链接到http://myapp.loc/books/index
)时,它就不起作用。
Web开发人员工具展示
Remote Address:127.0.0.1:80
Request URL:http://myapp.loc/books/index
Request Method:GET
Status Code:404 Not Found
我尝试在索引操作
下的books controller中添加一个语句die("here is my breakpoint");
我在应用加载时看到了这一点。但是,如果我把它拿出来让应用程序加载,然后点击基本上相同的链接,它甚至不会碰到那部分代码。
任何帮助将不胜感激。
路由器
<?php
/**
* 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'));
Router::connect('/', array('controller' => 'books', 'action' => 'index'));
/**
* ...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();
Router::mapResources('books', array('id'=>'[0-9A-Za-z]'));
Router::parseExtensions('json');
require CAKE . 'Config' . DS . 'routes.php';
答案 0 :(得分:0)
尝试添加第二行,如
Router::connect('/', array('controller' => 'books', 'action' => 'index'));
Router::connect('/books/*', array('controller' => 'books', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));