首页 > yii中$model->unsetAttributes()的作用是什么?

yii中$model->unsetAttributes()的作用是什么?

大家好:
请教一下,如下代码,其中的$model->unsetAttributes()是什么作用?为什么注释掉它视图中就显示“找不到数据”呢?

控制器中:
$model=new User('search');
$model->unsetAttributes();
…………

视图中:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
…………


使用了unsetAttributes后,相当于是吧当前的model中的关联信息清空了。清空了以后,再去使用新提交的数据,用于请求信息。

如果不使用unsetAttributes的话,相当于还保存了之前的数据内容,因而多个条件限制下,就会出来找不到数据

好长时间不用Yii了,不知道说的对不对。你也可以去官网看API。希望可以帮到你。

【热门文章】
【热门文章】