Hi Friends, Hi Friends, Some common question is difficult to how to create the layout on yii and how to work
echo $content;
so in this tutorial you may help the create the common layout..and understand the
echo $content;
=>In this tutorial default controller is Index Controller and default action is Index
1) so first you want to create the module on config/main.php file..
'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', //'password'=>'mmpandey', 'password'=>'admin', 'generatorPaths' => array( 'ext.giix-core', // giix generators ), 'ipFilters'=>array('127.0.0.1','::1'), ), 'rights'=>array( 'install'=>true, // Enables the installer. ), 'admin', 'customer', 'api', ),
and then generate the module URL (defind config/main.php) is like http://localhost/demo/admin/index
'urlManager'=>array( 'urlFormat'=>'path', //'showScriptName'=>false, 'rules'=>array( 'admin/' =>'admin/index/index', 'admin/login' =>'admin/index/login', 'admin/logout' =>'admin/index/logout', 'admin/<controller:\w+>/<action:\w+>'=>'admin/<controller>/<action>', 'customer/' =>'customer/index/index', 'customer/login' =>'customer/login', 'customer/logout' =>'customer/index/logout', 'customer/<controller:\w+>/<action:\w+>'=>'customer/<controller>/<action>', ), ),
2) i think the best way solution is you want to defined the defaultcontroller is indexcontroller and action index defined config/main.php
'defaultController'=>'index/index',
3) then after create the IndexController on module that extends the FrontCoreConteller apply the defult layout is main...
class IndexController extends FrontCoreController { /** * Declares class-based actions. */ public function actionIndx() { echo "Lorume Ipsum........" } }
4) Create the FrontCoreConterller.php
/** * Controller is the customized base controller class. * All controller classes for this application should extend from this base class. */ class FrontCoreController extends GxController { public $layout='main'; public function init() { parent::init(); } }
5)Finally you want to create the layout on modules folder
/views/layouts/main.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo SystemConfig::getValue('site_title');</title> <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" /> <!--[if IE]><script src="js/html5.js"></script><![endif]--> </head> <body> <section class="wapper"> <?php //p( yii::app()->customer) <?php echo $this->renderPartial('//layouts/header'); <?php //echo $this->renderPartial('//layouts/slider'); <?php echo $content; <?php echo $this->renderPartial('//layouts/footer'); </section> </body> </html>
in this tutorial every time call a default controller is index and action is call index so all modules default layout is main.php and write any code on index action fetch the data on
echo $content ;
i hope you got the my point...