Post model 里关系如下:
relations()
{
'userName'=>array(self::BELONGS_TO, 'User','userId'),
}
$post = Post::model->with('userName')->find();
我在views里试图引用:$post->userName时就会出现下面的错误:
Object of class User could not be converted to string
请大家帮忙,谢谢!
Post model 里关系如下:
relations()
{
'userName'=>array(self::BELONGS_TO, 'User','userId'),
}
$post = Post::model->with('userName')->find();
我在views里试图引用:$post->userName时就会出现下面的错误:
Object of class User could not be converted to string
请大家帮忙,谢谢!
你的$post->userName是User对象,想访问User对象的userName属性,用$post->userName->userName
因为relation名字的关系看起来怪怪的…
谢谢alex! 我找到答案了