yii框架的foreach 已经优化好了,以前我们遍历数组的时候是用foreach循环foreach ( as $key=>$value){ $user_model->$key=$value; }现在在YII框架里面可以直接这么使用,效果是一样的“$user_model->attributes=$_POST['Admin'];”注意:也许你会觉得在这个模型中没有这个“attributes”这个属性啊,原因是这样的:我们调用attributes一个模型里边不存在的属性,类就会自动执行魔术方法_set(); Read More
posted @ 2014-04-07 11:17
粉条
Views(441)
Comments(0)
Diggs(0)
YII 表单的验证可以在module目录下的xxx.php里面定义验证方法,设定需要验证的字段就行//用户表单验证,在模型里面设置一个方法,具体表单验证规则 public function rules(){ return array( array("name","required",'m... Read More
posted @ 2014-04-07 11:03
粉条
Views(145)
Comments(0)
Diggs(0)
今天来进行用户注册功能yii集成了很多验证框架,framework/validators下面,这个文件夹的最后一个文件CValidator.php 是总的验证信息,根据请求参数决定需要那种验证 如:url验证 “'url'=>'CUrlValidator',”email验证 'url'=>'CUrlValidator',1。定义数据表模型,models/xxx.php2,配置好控制器和试图的信息后,打开用户注册页面,把里面的form表单,用户输入框 和 label 用yii小部件代替3。在模型里面设置标签名字与数据库字 Read More
posted @ 2014-04-07 02:11
粉条
Views(248)
Comments(0)
Diggs(0)
textArea($user_model,'introduce',array('cols'=>50,'rows'=>5)); ?> Read More
posted @ 2014-04-07 01:55
粉条
Views(260)
Comments(0)
Diggs(0)
主要是添加separator属性(这里)$hoddy,$sex在控制器里面定义的数组,然后render传过来的 checkBoxList($user_model,'hobby',$hoddy,array('separator'=>'')); ?>radioButtonList($user_model,'sex',$sex,array('separator'=>''))?> Read More
posted @ 2014-04-07 01:36
粉条
Views(195)
Comments(0)
Diggs(0)
要使用小部件,可以先到总文件去找 framework/yiilite文件里面搜索“CAtiveForm”(如果觉得小部件的radio布局有点难看,可以在外面定义,具体可以在控制器里面定义)如下: function actionRegister(){ //实例化数据模型 $user_model=Admin::model(); $sex[1]='男'; $sex[2]='女'; $sex[3]='保密'; $this->render("register",array("user_model"=>$u Read More
posted @ 2014-04-07 00:33
粉条
Views(434)
Comments(0)
Diggs(0)

浙公网安备 33010602011771号