step 17: routes configuration cakephp blog project

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:

Routes Configuration:
Open up application's Routes script "routes.php" located at “/app/config/routes.php" then copy & past the blow code replacing the current.

/app/config/routes.php

   <?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'));"
that's it!!!

 

Finally open your browser and get effect of routes configuration in CakePHP Blog Project "http://localhost/cakeblog/" as follows:

 

Related Tutorial Examples

  1. step 14: delete post view controller cakephp blog
  2. step 15: adding element in cakephp blog
  3. step 16: passing data into element in cakephp blog
  4. MySQL greatest() Function String Value Example
  5. MySQL group concat function SQL Example
  6. MySQL concat function rows SQL Example
  7. MySQL concat function SQL Aliase Example
  8. MySQL IFNULL() function Example using PHP
  9. MySQL NULL comparison Example using PHP

No comments:

Post a Comment

leave your comments here..