关于文档里的 $model->attributes=$_POST['LoginForm'];

理论上说,


$model->attributes = $_POST['Msg'];


foreach($_POST['Msg'] as $name=>$value) {

	  if($name) {

		$model->$name=$value;

	 }

}

是等价的吧?

可是采用第一种方法为什么取不到表单里的下拉列表的值呢?总是 NULL, 采用第二种方法就可以。

表单内的性别取不到,


<?php echo $form->dropDownList($model, 'gender', array('1'=>'男', '2'=>'女')); ?>

好了,解决了,是因为


$model->attributes = $_POST['Msg'];

这种方式只能获取安全的特性。如果在验证规则里使用了某个特性,则认为是安全的,不然需要显示声明某个特性是安全的才可以采用第一种方式获取值。感觉这样挺好的。。。

After a model instance is created, we often need to populate its attributes with the data submitted by end-users.

参见,http://www.yiiframework.com/doc/guide/1.1/en/form.model#securing-attribute-assignments