1.安装:
windows:将php命令所在的文件夹路径加入到环境变量中,通过cmd命令:进入yii框架中的framework目录,执行:
php yiic webapp ../cms
linux:类似
2.载入模板
$this->render();会加载默认布局
$this->renderPartial();不会加载默认布局;或者在当前控制器中设置public $layout = false;
3.项目根目录:
Yii::app()->request->baseUrl;
或:Yii::app()->baseUrl;
4.访问modules:
http://myyii.com/index.php?r=模块/控制器/方法
5.重定向:
$this->redirect(array('index'));
6.获取GET/POST参数:
$id = Yii::app()->request->getParam('id');
7.页面跳转链接:
<a href="<?= $this->createUrl('add', array('id' => $val->id))?>">编辑</a>
8.gii使用方法:
a.配置文件main.phpreturn
array
(
……
'modules'
=>
array
(
'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'zrp',//设置密码 // If removed, Gii defaults to localhost only. Edit carefully to taste. 'ipFilters'=>array('127.0.0.1','::1'),//只允许本地访问 ),
)
……
)
访问(假定是cms项目):myyii.com/cms/index.php?r=gii
b.首先根据数据库名创建Model

c.根据model名创建curd

创建完之后,访问myyii.com/cms/index.php?r=user/index,账号密码都是admin,此时,curd操作就实现了。
9.设置页面公共部分(头、尾、左、右……)
(1)在/protected/views/layouts下面建立要载入的公共文件,自定义就好,如cms.php,示例如下:
header //公共头部 <div id="content"> <?php echo $content; //不同的部分?> </div><!-- content --> footer//公共尾部
(2)修改 /protected/components/Controller.php中的配置,将此项设置为步骤(1)中新建的名称:public $layout='//layouts/cms';
(3)调用模板的时候,要用$this->render()才行