Reputation: 17374
I am using Yii Framework. In the view, main.php, there is a reference to the $content block
<?php echo $content; ?>
I could not find it anywhere in the model or elsewhere in the demo project. Can someone shed light on this? Or may be this variable is never declared? I have not modified the demo project yet.
Upvotes: 3
Views: 4224
Reputation: 17374
Found answer from Yii Documentation / Layouts,
For example, a layout may contain a header and a footer, and embed the view in between, like this:
......header here......
<?php echo $content; ?>
......footer here......
where $content stores the rendering result of the view.
It is indeed all the text in one of the view (in my case index.php). $content basically takes the content of view. It is not declared anywhere and it is be default. As the answer said, you should not use declare/use $content in your code.
Upvotes: 1
Reputation: 301
All your controllers are derived from CController
class. CController
has a function named render
which you call it for rendering your views. It works like this:
beforeRender
is called.renderPartial
is called on your view file, and its output is stored in $output
.renderFile
is called on the layout file, with a parameter named content
like this:
$this->render(layoutFile, array('content'=>$output));
So the $content
is coming from here. You can see the actual code here: Source code, and documentation here: Documentation
Upvotes: 2
Reputation: 9402
The $content value in layout files contains the rendered content of the template specified as the first attribute of the render command. (It's automatically created so I wouldn't use "content" as an additional variable name or it could cause confusion.) The variables that you pass as an additional array argument in the render statement are made available to the template you are calling, not to the layout.
If you have nested layouts, the value of $content cascades from parent to child.
Upvotes: 2
Reputation: 12504
I think its being set from the controller which is calling this view.
In the controller look for something like the following
$this->render('main', array('content'=>"something here"));
Upvotes: 0