Question

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?

Was it helpful?

Solution

$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;

OTHER TIPS

Eliminate the $this for featured.

<?php echo print_r($featured, true); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top