step 17: routes configuration cakephp blog project
Let's have a look default landing page or homepage before routes configuration in CakePHP Blog Project "http://localhost/cakeblog/" as follows:
Now we want PostsController index view as default landing page or homepage, to do so we need to modify "/app/config/routes.php" as follows:
Open up application's Routes script "routes.php" located at “/app/config/routes.php" then copy & past the blow code replacing the current.
<?php /* SVN FILE: $Id$ */ /** * Short description for file. * * 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). * * PHP versions 4 and 5 * * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @package cake * @subpackage cake.app.config * @since CakePHP(tm) v 0.2.9 * @version $Revision$ * @modifiedby $LastChangedBy$ * @lastmodified $Date$ * @license http://www.opensource.org/licenses/mit-license.php The 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/views/pages/home.ctp)... */ Router::connect('/', array('controller' => 'posts', 'action' => 'index', 'home')); /** * ...and connect the rest of 'Pages' controller's urls. */ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); ?>
What actually done?
Simple, just replace the line "Router::connect ('/', array('controller'=>'pages', 'action'=>'display', 'home'));"
with "Router::connect ('/', array('controller'=>'posts', 'action'=>'index'));"
Finally open your browser and get effect of routes configuration in CakePHP Blog Project "http://localhost/cakeblog/" as follows:
Related Tutorial Examples
- step 14: delete post view controller cakephp blog
- step 15: adding element in cakephp blog
- step 16: passing data into element in cakephp blog
- MySQL greatest() Function String Value Example
- MySQL group concat function SQL Example
- MySQL concat function rows SQL Example
- MySQL concat function SQL Aliase Example
- MySQL IFNULL() function Example using PHP
- MySQL NULL comparison Example using PHP