是否应该更改数据在模型或视图中的显示方式?(PHP-YII)

是否应该更改数据在模型或视图中的显示方式?(PHP-YII),php,yii,Php,Yii,我最近在MVC实践中读到,几乎所有与查询相关的数据都应该在模型中。但是,我感兴趣的是,当您使用外键更改应在模型或视图中显示的查询对象的名称时 下面是我正在使用的示例 // the id is being saved from the model $callfood=Food::model()->getfoodlist(); // in this part $callfood is using a foreign key to display the 'food_id'

我最近在MVC实践中读到,几乎所有与查询相关的数据都应该在模型中。但是,我感兴趣的是,当您使用外键更改应在模型或视图中显示的查询对象的名称时

下面是我正在使用的示例

     // the id is being saved from the model 
$callfood=Food::model()->getfoodlist();
     // in this part $callfood is using a foreign key to display the 'food_id' as the   names of the food 
     echo $form->dropDownList($model, 'food_id',$callfood); ?>

dropDownList代码应该在视图中,这对我来说是有意义的,但我确实觉得我正在改变它在dropDownList中的显示/保存方式。我们是否应该继续这样做?或者,如果我想更改视图并保留下拉列表,是否应该将其推送到模型中,以便可以重用它

这取决于工作流的设置方式。但基本上,您将模型保存在一个变量中,并将其发送到视图。然后可以使用dropDownList($model,'food\u id',$f\u model->getfoodlist())。我建议您仔细了解PHP和Yii的工作原理;)