04:24:19.273058 warning application
Failed to set unsafe attribute "username" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273178 warning application
Failed to set unsafe attribute "password" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273281 warning application
Failed to set unsafe attribute "user_email" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273381 warning application
Failed to set unsafe attribute "user_qq" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273478 warning application
Failed to set unsafe attribute "user_tel" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273572 warning application
Failed to set unsafe attribute "user_sex" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273665 warning application
Failed to set unsafe attribute "user_xueli" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273761 warning application
Failed to set unsafe attribute "user_hobby" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
04:24:19.273855 warning application
Failed to set unsafe attribute "user_introduce" of "User".
in D:\xampp\htdocs\2013819\shop\protected\controllers\UserController.php
(59)
in D:\xampp\htdocs\2013819\shop\index.php (16)
UserController.php
/**
-
用户控制器
-
13-5-7 下午8:30
*/
class UserController extends Controller{
/*
* 实现用户注册功能:
* 1. 展现注册表单
* 2. 收集数据、校验数据、存储数据
*/
function actionRegister(){
//实例化数据模型对象user
$user_model = new User();
/**
* renderPartial不渲染布局
* render会渲染布局
*/
//$this ->renderPartial('register');
//性别信息
$sex[1] = "男";
$sex[2] = "女";
$sex[3] = "保密";
//定义学历
$xueli[1] = "-请选择-";
$xueli[2] = "小学";
$xueli[3] = "初中";
$xueli[4] = "高中";
$xueli[5] = "大学";
//定义爱好信息
$hobby[1] = "篮球";
$hobby[2] = "足球";
$hobby[3] = "排球";
$hobby[4] = "棒球";
//如果用户有注册表单
if(isset($_POST['User'])){
//给模型收集表单信息
//foreach($_POST['User'] as $_k => $_v){
// $user_model -> $_k = $_v;
//}
//上边的foreach,在yii框架里边有优化,使用模型属性attributes来进行优化
//attributes 属性已经把foreach集成好了,我们可以直接使用
$user_model -> attributes = $_POST['User'];
//实现信息存储
if($user_model -> save())
echo 'success';
//$this ->redirect ('./index.php'); //重定向到首页
}
$this -> render('register',array('user_model'=>$user_model,'sex'=>$sex,'xueli'=>$xueli,'hobby'=>$hobby));
}
}
注册表单
<!--放入view具体内容-->
<div class="block box">
<div class="usBox">
<div class="usBox_2 clearfix">
<div class="logtitle3"></div>
<?php $form = $this -> beginWidget('CActiveForm'); ?>
<table cellpadding="5" cellspacing="3" style="text-align:left; width:100%; border:0;">
<tbody>
<tr>
<td style="width:13%; text-align: right;">
<?php echo $form->label($user_model, 'username'); ?>
</td>
<td style="width:87%;">
<?php echo $form->textField($user_model,'username',array('class'=>'inputBg','id'=>'User_username')); ?>
<!--表单验证失败显示错误信息-->
<?php echo $form ->error($user_model,'username'); ?>
</td>
</tr>
<tr>
<td align="right">
<?php echo $form->label($user_model, 'password'); ?>
</td>
<td>
<?php echo $form->passwordField($user_model,'password',array('class'=>'inputBg','id'=>'User_password')); ?>
<?php echo $form ->error($user_model,'password'); ?>
</td>
</tr>
<!-- <tr>
<td align="right"><label for="User_password2">密码确认</label></td>
<td>
<input class="inputBg" size="25" name="User[password2]" id="User_password2" type="password" />
</td>
</tr>-->
<tr>
<td align="right"><?php echo $form->label($user_model, 'user_email'); ?></td>
<td>
<?php echo $form->textField($user_model,'user_email',array('class'=>'inputBg','id'=>'User_user_email')); ?>
</td>
</tr>
<tr>
<td align="right"><?php echo $form->label($user_model, 'user_qq'); ?></td>
<td>
<?php echo $form->textField($user_model,'user_qq',array('class'=>'inputBg','id'=>'User_user_qq')); ?>
</td>
</tr>
<tr>
<td align="right"><?php echo $form->label($user_model, 'user_tel'); ?></td>
<td>
<?php echo $form->textField($user_model,'user_tel',array('class'=>'inputBg','id'=>'User_user_tel')); ?>
</td>
</tr>
<tr>
<!--radioButtonList($model,$attribute,$data,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model, 'user_sex'); ?></td>
<td>
<?php echo $form->radioButtonList($user_model,'user_sex',$sex,array('separator'=>'&nbsp;')); ?>
</td>
</tr>
<tr>
<!--dropDownList($model,$attribute,$data,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model, 'user_xueli'); ?></td>
<td>
<?php echo $form -> dropDownList($user_model,'user_xueli',$xueli); ?>
</td>
</tr>
<tr>
<!--checkBoxList($model,$attribute,$data,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model, 'user_hobby'); ?></td>
<td>
<?php echo $form -> checkBoxList($user_model,'user_hobby',$hobby,array('separator'=>'&nbsp;')); ?>
</td>
</tr>
<tr>
<!--textArea($model,$attribute,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model, 'user_introduce'); ?></td>
<td>
<?php echo $form -> textArea($user_model,'user_introduce',array('cols'=>50,'rows'=>5)); ?>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="left">
<input name="Submit" value="" class="us_Submit_reg" type="submit" />
</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
</tbody>
</table>
<?php $this->endWidget(); ?>
</div>
</div>
</div>
<!--放入view具体内容-->
</div>