I'm currently looking for a solution to remove the "Pages" from the URL, but it doesn't make it difficult to add a controller.
I looked around and searched on Google for a solution, but the best solution they could give was the following:
Router::Connect('/*', array('controller' => 'pages', 'action' => 'display'));
Link Example
But the problem with this solution is that every time I want to add a controller, I need to add the following lines to the config / routers.php file
Router::Connect('/Users/:action/, array('controller' => 'Users');
Router::Connect('/users/:action/, array('controller' => 'Users');
The reason I added these two lines is because I did not want the url to be case sensitive.
I also know that it’s not as often as the site is “COMPLETED” that the controllers change.
So my solution was as follows:
$url = array_filter(explode("/", Router::url()));
$Controllers = App::objects('controller');
$CleanControllers = array();
foreach($Controllers as $Controller) {
$CleanControllers[] = strtolower(str_replace('Controller', '', $Controller));
}
if(!in_array(strtolower(reset($url)), $CleanControllers)) {
Router::connect('/', array('controller' => 'Pages', 'action' => 'display', 'home'));
Router::connect('/*', array('controller' => 'Pages', 'action' => 'display'));
}
CakePlugin::routes();
require CAKE . 'Config' . DS . 'routes.php';
So my question is a KILLER performance solution? If so, does anyone know a better solution?
, CakePHP, , SUPER Advanced routing... .
CAKEPHP 2.1
!