Difference between #2 and #3 of
Putting Function To Be Called In View

Changes

Title unchanged

Putting Function To Be Called In View

Category unchanged

Tips

Yii version unchanged

Tags unchanged

view, render

Content changed

Sometimes we need some complicated view to be displayed (such as generating complicated table). Most people suggest that in MVC the View must be as simple as possible (don't have too much loops, etc). So what we have to do is to hide away the complex code by putting it at somewhere else. The following are few places options to keep the function: 1. We can add the function in the Model, so in the view file we just can call the model's method. The drawback of this method is model is not supposed to be put some viewing function. _So it's not adviseable to put the function related viewing or output result to the screen in there._
[...]
```


 
3
3. Put the function to the controller. If the function only used in one view. Then it is better to putt into the Controller.
 
 
 
4
. Use the view file. Because the CController's render() and renderPartial() methods can return value instead displaying it, using view as the function is possible. That's mean we can put the function into certain view file (preferably in one folder with the caller if the caller only one). To make the render return value we must specified the third parameter to be 'true'.
 




```php
//in the _view_function.php
[...]
5 1
5 followers
Viewed: 52 387 times
Version: 1.1
Category: Tips
Tags: render, view
Written by: junxiong
Last updated by: junxiong
Created on: Dec 28, 2010
Last updated: 13 years ago
Update Article

Revisions

View all history