如何向 Phalcon 应用程序添加新视图


How to add new view to Phalcon app?

我对Phalcon PHP如何呈现其视图感到非常困惑。我想创建一个名为"管理器"的新页面。

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

我在 volt 文件中添加了一些文本以检查它是否有效。当我去/manager/时,什么都没有出现。

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

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

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

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

在你有兴趣渲染/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
    }
}