我想在Yii中显示最后4页?

时间:2014-05-05 20:14:12

标签: php yii

学习编程Yii,我想显示最后4页:

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); ?>

后一个文件没有显示任何内容,应该是包含数据的数组,我该如何获取?

2 个答案:

答案 0 :(得分:0)

消除特色的$ this。

<?php echo print_r($featured, true); ?>

答案 1 :(得分:0)

$this->render('/layouts/start/start', array('featured'=>$featured));

在这里,您要将值的数组(关联数组)发送到视图。您可以通过调用数组Key来访问这些值。

所以,你的代码应该是

<?php echo print_r($featured); ?>

另一个例子。

$this->render('myView', array('myName'=>'Hearaman','myAge'=>25));

我将我的姓名和年龄发送给View。要显示我的姓名和年龄,我应该拨打密钥

echo $myName;
echo $myAge;