【问题标题】:How to add new view to Phalcon app?如何向 Phalcon 应用程序添加新视图?
【发布时间】:2015-01-18 14:55:10
【问题描述】:

我对 Phalcon PHP 如何呈现其视图完全感到困惑。我想创建一个名为“manager”的新页面。

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

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

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

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

【问题讨论】:

  • 我们可以看看你的控制器的代码,编辑成你的问题吗?
  • 我已将其添加到顶部
  • 在大多数框架中,您需要执行“渲染”操作,指定视图文件。 Phalcon 是这样吗?
  • 我真的不知道,是否有人可以指导我如何创建一个很棒的视图。
  • 啊,好像view files are rendered automatically。好的,您的日志中有任何错误吗?调试时间!另外,你需要在这个控制器中使用*Action 方法吗?

标签: php phalcon phalcon-routing


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 2013-05-22
    • 1970-01-01
    • 2010-09-15
    相关资源
    最近更新 更多