php318
(Php318)
August 13, 2009, 1:23am
1
$model->attributes=$_POST;
为什么
$model=new User;
$model->username=$_POST[‘username’];
var_export($_POST);
$model->attributes=$_POST;
var_export($model->attributes);
exit;
$_POST数据为array ( ‘username’ => ‘test3’, ‘company’ => ‘test’, ‘linkman’ => ‘test’, ‘email’ => ‘demo@qq.com’, ‘phone’ => ‘1234567’, ‘submit’ => ‘提交’, )
$model->attributes数据为array ( ‘username’ => ‘test3’, ‘id’ => NULL, ‘company’ => NULL, ‘linkman’ => NULL, ‘email’ => NULL, ‘phone’ => NULL, ‘created’ => NULL, ‘updated’ => NULL, )
有谁知道那里错了?
imehesz
(Imehesz)
August 13, 2009, 12:27pm
3
I had the exact same problem, but only with my users table (User model!) It worked if I assigned the values 1 by 1. ie:
...
$user -> setAttribute( 'username', $_POST['username'] );
...
I cried myself to sleep many times with this last week! It only happens with the User model. So weird.
–iM
qiang
(Qiang Xue)
August 13, 2009, 12:31pm
4
@imehesz : please check your safeAttributes().
php318
(Php318)
August 18, 2009, 2:16am
5
<?php
class User extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @return CActiveRecord the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'User';
}
}
估计真的和User这个名有关,因为我已经遇到过文件名用admin.php作为程序入口,而出现错误,
改成其他的文件名就不会。