简体   繁体   中英

:action/* element is giving missing controller error

<?php
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('/blog/:action/*', array('controller' => 'posts', 'action' =>'index'));
/**
* 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';
?>

here is my route.php file when i try to access website/blog it would throw me an error saying blog controller is missing. but when i change "/blog/:action/*" to "/blog" it wil work fine what am i doing wrong ?? please help thanks.

Ok, based on your comments, try this

//redirects "website/items/view/1" to "website/blogs/view/1"
Router::connect('/items/:action/*', array('controller' => 'blogs'));

//redirects "/blog" to "website/items/index"
Router::connect('/blog', array('controller' => 'items', 'action' =>'index'));

But it seems awfully confusing? why redirect blog to items ( "website/blog it redirect me to website/Item/index" ) and items to blog ( "website/Items/view/1 it redirects me to website/blog/View/1" )? Shouldn't you just change those actions to the controller where you want to have them?

And please read the routing docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM