4

What is difference between view.php and _view.php in Yii?

Where I should use from _view or view in Yii?

By render() or renderPartial() I can render both? hasn't problem in performance or anything?

Moe Far
  • 2,742
  • 2
  • 23
  • 41
Chalist
  • 3,160
  • 5
  • 39
  • 68
  • Its just two file names ... – Akhil Thayyil Dec 31 '12 at 08:46
  • 1
    There's no functional difference, only a semantical one - an underscore prefix is an unofficial indicator "this is a private/helper file, don't use it outside its intended context". Many other coding conventions agree with this use of the underscore prefix. – DCoder Dec 31 '12 at 08:48

1 Answers1

7

They are simply filenames, but by default view.php is used with a render() and _view.php is used with a renderPartial() (in the default Yii web application).

So if we stick to this convention, any view rendered by render() will be a "normal" file name, and anything rendered with a renderPartial() will have a prefixing _underscore.

Here is the difference between render and renderPartial (from here):

render() is commonly used to render a view that corresponds to what a user sees as a "page" in your application. It first renders the view you have specified and then renders the layout for the current controller action (if applicable), placing the result of the first render into the layout. It then performs output processing (which at this time means automatically inserting any necessary <script> tags and updating dynamic content) and finally outputs the result.

renderPartial() is commonly used to render a "piece" of a page. The main difference from render() is that this method does not place the results of the render in a layout. By default it also does not perform output processing, but you can override this behavior using the $processOutput parameter.

Community
  • 1
  • 1
Brett Gregson
  • 5,867
  • 3
  • 42
  • 60