如何向Phalcon app添加新视图?

时间:2015-01-18 14:55:10

标签: php phalcon phalcon-routing

我对Phalcon PHP如何呈现其观点完全感到困惑。我想创建一个名为" manager"。

的新页面

根据我的理解,通过创建控制器,我可以将其链接到视图。我创建了一个名为ManagerController.php的控制器,然后在views/manager/index.volt中添加了一个视图。

我在伏特文件中添加了一些文本来检查它是否有效。当我去/manager/时,没有任何显示。

我这样做是正确的还是我必须在某处分配视图?

class ManagerController extends ControllerBase
{
    public function initialize()
    {
        $this->tag->setTitle('Files/My Files');
        parent::initialize();
    }
}

1 个答案:

答案 0 :(得分:2)

控制器上的初始化函数是构造控制器后运行的事件

为了显示该控制器的视图,至少需要设置索引操作

在您感兴趣的是渲染/ manager /的路由时,这将对应于indexAction

class ManagerController extends ControllerBase
{
    public function initialize()
    {
        $this->tag->setTitle('Files/My Files');
        parent::initialize();
    }
    public function indexAction()
    {
        // This will now render the view file located inside of
        // /views/manager/index.volt

        // It is recommended to follow the automatic rendering scheme
        // but in case you wanted to render a different view, you can use:
        $this->view->pick('manager/index');
        // http://docs.phalconphp.com/en/latest/reference/views.html#picking-views
    }

    // If however, you are looking to render the route /manager/new/
    // you will create a corresponding action on the controller with RouteNameAction:
    public function newAction()
    {
        //Renders the route /manager/new
        //Automatically picks the view /views/manager/new.volt
    }
}