CakePHP $ this-> set()在Pages Controller中不起作用

Dou*_*ura 1 php cakephp

我正在使用CakePHP进行开发,这是我的页面控制器:

<?php
class PagesController extends AppController
{
    var $name = 'Pages';
    var $helpers = array('Html', 'Session');
    var $uses = array();

    function display()
    {
        $path = func_get_args();

        $count = count($path);
        if (!$count) {
            $this->redirect('/');
        }
        $page = $subpage = $title_for_layout = null;

        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $title_for_layout = Inflector::humanize($path[$count - 1]);
        }
        $this->set(compact('page', 'subpage', 'title_for_layout'));
        $this->render(implode('/', $path));

        $this->loadModel('Curso', 2);

        $select = $this->Curso->query("SELECT * FROM cursos ORDER BY `cursos`.`created` DESC  LIMIT 2;");
        $this->set('cursos', $select);
        //$this->set($select);

    }
}
Run Code Online (Sandbox Code Playgroud)

但是$this->set('cursos', $select);不行,这是错误:

Notice (8): Undefined variable: cursos[APP/views/pages/home.ctp, line 36].
Run Code Online (Sandbox Code Playgroud)

有人可以帮帮我吗?

hel*_*dre 7

那是因为你在$this->render()通话后设置了它.渲染调用是在加载和执行视图时.