【问题标题】:Phalcon PHP still going to default template even after view->pick即使在 view->pick 之后,Phalcon PHP 仍然会使用默认模板
【发布时间】:2014-07-05 08:15:28
【问题描述】:

大家好,我有这样的基础课

class IndexController extends ControllerBase
{


    public function onConstruct(){

    }

    public function indexAction()
    {

        return $this->view->pick(array("login/login"));         
    }   

}

我希望它呈现登录文件夹和 login.volt 中的内容

事情是,它正在渲染它,但它也在渲染 index.volt 中的内容,并且具有以下内容

<!DOCTYPE html>
<html>
    <head>
        <title>Phalcon PHP Framework</title>
    </head>
    <body>
        {{ content() }}
    </body>
</html>

所以我得到了双 html 双体等

谁能告诉我为什么会这样和/或建议修复。谢谢大家

【问题讨论】:

    标签: php twig phalcon volt


    【解决方案1】:

    尝试使用 setMainView 方法

    class IndexController extends ControllerBase
    {
    
    
        public function onConstruct(){
    
        }
    
        public function indexAction()
        {
    
            return $this->view->setMainView("login/login");         
        }   
    
    }
    

    setMainView 方法用于设置默认视图。只需将视图名称作为参数。 http://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_View.html

    【讨论】:

      【解决方案2】:

      删除return 关键字。我相信它正在获取您想要的视图,然后将其返回到基本模板中。

      【讨论】:

        【解决方案3】:

        在 phalcon 中有两种使用视图的方法

        $this->view->pick(array('login/login')); // with  layout 
        
        $this->view->pick('login/login'); // without layout
        

        【讨论】:

          【解决方案4】:

          您只能通过setRenderLevel设置操作视图

          public function indexAction()
          {
              $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
              return $this->view->pick(array("login/login"));         
          }   
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2019-06-30
            • 2016-12-13
            • 1970-01-01
            • 2014-07-31
            • 2013-04-03
            • 2015-03-10
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多