prevent view to access model relations

hello everyone

currently we can access model relations in view.

like this:


$model->post->title;

this mean "view connected to the database" and i think this is not right !!!

i want view can access relation if fill or loaded in controller or widget before render.

like this:


public function actionView(){

  $model = comment::model()->with('post')->findAll();

  $this->render('view',array('model'=>$model));

}

if action pass model without “with(‘post’)”, view can’t access $model->post->title and throw exception.

how to design this functionality as well as possible?

regards.

[indent]

[/indent]

Hi MR.omid,

Probably you might want to follow the MVC design pattern very strictly, and I do agree with you that MVC is a good thing. But frankly saying, I don’t see much benefit in your proposal in this particular case.

By writing “echo $model->post->title”, the view states that the model has some object called “post” and “post” in tern has some string attribute called “title”. It doesn’t state that “post” is a relational data of the model that has to be retrieved from a db table. All those details about the model are hidden from the view. Isn’t it enough?

I absolutely agree with softark

If you want anyway to do that you have to create methods (not actions) in controller (or widget) to take more access control for this task