谁一开始就是大神?

Yii更新数据问题[1.1]

在登录中,验证通过更新用户表的ip和时间
数据库中 time 是时间戳 为 Int
我查询的代码

$username = $loginForm->attributes['username'];
$user = User::model()->find('username=:name',array(':name'=>$username)); 
//$user->time=time();
//$user->ip=Yii::app()->request->userHostAddress;
var_dump($user);die;
$user->save();

网页打印的代码

array (size=6)
      'id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'password' => string '21232f297a57a5a743894a0e4a801fc3' (length=32)
      'ip' => string '127.0.0.1' (length=9)
      'time' => string '1435394244' (length=10)
      'class' => string '1' (length=1)

我组装数组的代码

Yii::app()->session['logintime'] = time();
$username = $loginForm->attributes['username'];
$user = User::model()->find('username=:name',array(':name'=>$username)); 
$user->time=time();
$user->ip=Yii::app()->request->userHostAddress;
var_dump($user);die;
$user->save();

网页显示的

    array (size=6)
      'id' => string '1' (length=1)
      'username' => string 'admin' (length=5)
      'password' => string '21232f297a57a5a743894a0e4a801fc3' (length=32)
      'ip' => string '127.0.0.1' (length=9)
      'time' => int 1435553625
      'class' => string '1' (length=1)

数据库结构中时间为int型。
最后更新提交的时候提示

CDbException
Column name must be either a string or an array.
C:\wamp\www\cms\framework\db\schema\CDbCommandBuilder.php(831)

model User的代码贴一下

赞(0) 打赏
未经允许不得转载:菜鸟之家 » Yii更新数据问题[1.1]

评论 抢沙发

登录

找回密码

注册