Studying Programming Yii, I want to display the last 4 pages:
SiteController.php
public function actionStart()
{
$featured = Page::model()->findAllByAttributes(
array(),
$condition = 'featured = :featureId',
$params = array(
':featureId' => 1,
)
);
$this->render('/layouts/start/start', array('featured'=>$featured));
}
/layouts/start/start.php
<?php print_r($this->featured); ?>
The latter file does not display anything, and should be an array with the data, how do I get it?
$this->render('/layouts/start/start', array('featured'=>$featured));
Here, you are sending array(association array) of values to the View. You can access these values by calling the array Key
.
So, your code should be
<?php echo print_r($featured); ?>
Another example.
$this->render('myView', array('myName'=>'Hearaman','myAge'=>25));
I'm sending my name and age to View. To show my name and age, i should call the keys
echo $myName;
echo $myAge;
Eliminate the $this for featured.
<?php echo print_r($featured, true); ?>