1 http://localhost/yii/testdrive/index.php
路由:http://localhost/yii/testdrive/index.php?r=site/index
2 assets:一般放置默认css js img
3 protected:中config 可以放置常量文件,我们网站的一些常量
建一个constants.php
4 index.php:如果配置文件要生效就必须在这个文件中引入
require_one(dirname(__FILE__).'/protected/config/contants.php');
5 components:中包含了controler类,是通过conifg/main.php主配置文件中引入的
6 我们系统默认的布局文件是layout/column1;
但是有时候我们要自定义自己的布局文件所以可以自己
创建layout,然后在components/controller.php 中指定
7 布局文件的关系
控制器渲染试图renderPartial()此方法不会渲染布局
render()这个方法会渲染布局
8 yii 自己有一个模块机制,可以棒子我们实现后台的搭建
模块:有自己独立的控制器,独立的试图,独立的模型,其不可以单独部署
我们的创建模块:gii(自动代码生成工具)
gii在yii里半三以模块形式存。在config/main.php配置文件里边开gii 模块以便使用
通过路由的形式来访问该模块http://localhost/yii/testdrive/index.php?r=模块名字
http://localhost/yii/testdrive/index.php?r=gii
gii可以自动生成代码 向houtai这个模块就是用gii自动生成的
gii 生成crud前必须建立相应的表 还有定义的modeol
9 widget 生成表单
************************view*******************
$form = $this->beginWidget('CActiveForm');
echo $form->textField($loginForm,'username',array('id'=>'userName'));
$this->endWidget();
***********************controller*************
要把表单modal 传递给view
$loginForm = new LoginForm();
$this->render('login',array('loginForm'=>$loginForm));
10 验证马
********view*********
在weiget下
echo "<div class='captcha'>";
$this->widget('CCaptcha',array('showRefreshButton'=>false,
'clickableImage'=>true,'imageOptions'=>array('alt'=>'点击换图',
'title'=>'点击换图','style'=>'cursor:pointer'
)));
*******controller****
public function actions(){
return array(
'captcha' => array(
'class' => 'system.web.widgets.captcha.CCaptchaAction',
'height' =>25,
'width' => 80,
'minLength' => 4,
'maxLength' => 4
),
);
}
其中远征嘛相关函数在ccaptchaaction中system表示framework
*******修改CCaptchaAction函数***********
修改run函数中的$this->renderImage($this->getVerifyCode(这个本来是空的改成true))
*****验证规则****
在LoginForm 中的rules 加入
//验证码规则
array('captcha','captcha','message'=>"验证马错误"),
***点击验证码没有效果*问题处理***
因为我们使用了rendaPartical 是没使用到布局文件的这样很多jquery js 都没有调用到
所以使用render然后自己建一个布局
11 为了区分后台登陆和前台登陆我们应该在houtai module中的HoutaiModule.php init()方法加入
Yii::app()->setComponents(array(
'user' => array('stateKeyPrefix' => 'houtai'),
));
12 超链接和跳转
$this->createUrl('article/index',array('aid'=>3)); //超链接
跳转
$this->redirect(array('控制器/方法'))
如果是当前控控制器下的:
$this->redirect(array('index'))
13 session 的使用
设置:Yii:app()->session['logintime'] = time;
调用:Yii:app()->session['logintime']
清除:Yii:app()->session->clear(); destroy();
14:退出登陆
Yii:app()->user->logout();
15;标签的作用
写在model中方便其它叶面重用,在attributeLabels()方法中
然后如果在view中调用$form->labelEx($loginForm,'name')
16:rule
在rules函数中可以设置表单的一些规则
自定义方法
array('password','check_passwd')
public function check_passwd(){
$userInfo = $this->find('name=:name',array(':name'=>yii:app()->user->name))
if(md5($this->password) != $userInfo->password){
$this->addError('password','密码不正确');
}
}
yii内部函数
array('password2','compare','compareAttribute'=>'password1','message'=>'密码不一样')
17 客户端验证
$form = $this->beginWidget('CActiveForm'); //这是后台验证
$form = $this->beginWidget('CActiveForm',array(
'enableClientValidation' => true,
'clientOptions' = array(
'validateOnSubmit' => true,
),
));
18 闪存
可以在controller中哦哦设置 Yii::app()->user->setFlash('s','添加成功哦哦');
然后在试图中调用
if(Yii::app()->user->hasFlash('s')){
echo Yii::app()->user->getFlash('s');
}
19 开启调试信息
在main.pphp
log中将
/*
array(
'class'=>'CWebLogRoute',
),
*/
路由:http://localhost/yii/testdrive/index.php?r=site/index
2 assets:一般放置默认css js img
3 protected:中config 可以放置常量文件,我们网站的一些常量
建一个constants.php
4 index.php:如果配置文件要生效就必须在这个文件中引入
require_one(dirname(__FILE__).'/protected/config/contants.php');
5 components:中包含了controler类,是通过conifg/main.php主配置文件中引入的
6 我们系统默认的布局文件是layout/column1;
但是有时候我们要自定义自己的布局文件所以可以自己
创建layout,然后在components/controller.php 中指定
7 布局文件的关系
控制器渲染试图renderPartial()此方法不会渲染布局
render()这个方法会渲染布局
8 yii 自己有一个模块机制,可以棒子我们实现后台的搭建
模块:有自己独立的控制器,独立的试图,独立的模型,其不可以单独部署
我们的创建模块:gii(自动代码生成工具)
gii在yii里半三以模块形式存。在config/main.php配置文件里边开gii 模块以便使用
通过路由的形式来访问该模块http://localhost/yii/testdrive/index.php?r=模块名字
http://localhost/yii/testdrive/index.php?r=gii
gii可以自动生成代码 向houtai这个模块就是用gii自动生成的
gii 生成crud前必须建立相应的表 还有定义的modeol
9 widget 生成表单
************************view*******************
$form = $this->beginWidget('CActiveForm');
echo $form->textField($loginForm,'username',array('id'=>'userName'));
$this->endWidget();
***********************controller*************
要把表单modal 传递给view
$loginForm = new LoginForm();
$this->render('login',array('loginForm'=>$loginForm));
10 验证马
********view*********
在weiget下
echo "<div class='captcha'>";
$this->widget('CCaptcha',array('showRefreshButton'=>false,
'clickableImage'=>true,'imageOptions'=>array('alt'=>'点击换图',
'title'=>'点击换图','style'=>'cursor:pointer'
)));
*******controller****
public function actions(){
return array(
'captcha' => array(
'class' => 'system.web.widgets.captcha.CCaptchaAction',
'height' =>25,
'width' => 80,
'minLength' => 4,
'maxLength' => 4
),
);
}
其中远征嘛相关函数在ccaptchaaction中system表示framework
*******修改CCaptchaAction函数***********
修改run函数中的$this->renderImage($this->getVerifyCode(这个本来是空的改成true))
*****验证规则****
在LoginForm 中的rules 加入
//验证码规则
array('captcha','captcha','message'=>"验证马错误"),
***点击验证码没有效果*问题处理***
因为我们使用了rendaPartical 是没使用到布局文件的这样很多jquery js 都没有调用到
所以使用render然后自己建一个布局
11 为了区分后台登陆和前台登陆我们应该在houtai module中的HoutaiModule.php init()方法加入
Yii::app()->setComponents(array(
'user' => array('stateKeyPrefix' => 'houtai'),
));
12 超链接和跳转
$this->createUrl('article/index',array('aid'=>3)); //超链接
跳转
$this->redirect(array('控制器/方法'))
如果是当前控控制器下的:
$this->redirect(array('index'))
13 session 的使用
设置:Yii:app()->session['logintime'] = time;
调用:Yii:app()->session['logintime']
清除:Yii:app()->session->clear(); destroy();
14:退出登陆
Yii:app()->user->logout();
15;标签的作用
写在model中方便其它叶面重用,在attributeLabels()方法中
然后如果在view中调用$form->labelEx($loginForm,'name')
16:rule
在rules函数中可以设置表单的一些规则
自定义方法
array('password','check_passwd')
public function check_passwd(){
$userInfo = $this->find('name=:name',array(':name'=>yii:app()->user->name))
if(md5($this->password) != $userInfo->password){
$this->addError('password','密码不正确');
}
}
yii内部函数
array('password2','compare','compareAttribute'=>'password1','message'=>'密码不一样')
17 客户端验证
$form = $this->beginWidget('CActiveForm'); //这是后台验证
$form = $this->beginWidget('CActiveForm',array(
'enableClientValidation' => true,
'clientOptions' = array(
'validateOnSubmit' => true,
),
));
18 闪存
可以在controller中哦哦设置 Yii::app()->user->setFlash('s','添加成功哦哦');
然后在试图中调用
if(Yii::app()->user->hasFlash('s')){
echo Yii::app()->user->getFlash('s');
}
19 开启调试信息
在main.pphp
log中将
/*
array(
'class'=>'CWebLogRoute',
),
*/