创建与设置默认控制器与载入模板
1.yii框架默认载入site控制器
2.localhost/yii/yii_1_1_17/cms/index.php?r=index/index r是route路由的缩写,index(控制器)/index(方法)
3.设置默认访问控制器、路径
protected-config-main.php,
'defaultController'=>'Index',
4.载入视图
$this->render();//默认同时载入布局
$this->renderPartial();//默认不载入布局,也不能载入框架自带的jquery
默认载入布局的位置:
protected-components-Controller.php
public $layout='//layouts/column1';
5.布局
在views/layouts下面的文件式布局文件,公共区域,用render自动加载的文件
布局内容
上边公用头部
中间<?php echo $content; ?>
下边公用尾部
6.载入外部文件(css/image/js等)
Yii::app()->request->baseUrl;
Yii::app()返回的是你在index.php里创建的CWebApplication实例。
在一次请求处理过程中,这是个唯一的实例。主要负责一些全局性的功能模块。
7.给视图分配数据
$data = array(
'title'=>'123',
..
);
$this->renderPartial('index',$data);
8.扩展自定义函数
在protected目录下建立functions.php文件
在单入口index中引入函数:
require_once('./protected/functions.php');