I am new to yii. I have used cake and CI before. I used gii to create my models, views, and controllers. One of my models is named Hero. I don’t understand the generated code for HeroController.actionView() and views/hero/_view.php.
The code for HeroController.actionView() loads the model into a variable named $model.
/**
* Displays a particular model.
*/
public function actionView()
{
$this->render('view',array(
'model'=>$this->loadModel(),
));
}
However on _view.php the $model fields are referenced like so: $data->name. Why is that? Where did $model go?
<div class="view">
<b><?php echo CHtml::encode($data->getAttributeLabel('name')); ?>:</b>
<?php echo CHtml::encode($data->name); ?>
<br />
<b><?php echo CHtml::encode($data->getAttributeLabel('description')); ?>:</b>
<?php echo CHtml::encode($data->description); ?>
<br />
</div>
According to the docs for the render method there should be a variable named $model in the view.
*...
* @param array data to be extracted into PHP variables and made available to the view script
*...
*/
public function render($view,$data=null,$return=false)