【问题标题】:Have problems with using Volt with phalcon将 Volt 与 phalcon 一起使用时遇到问题
【发布时间】:2012-11-21 21:58:03
【问题描述】:

继承在 volt 模板中不起作用的接缝。

Phalcon 版本是 0.6.1

有一个文件结构:

  • 浏览量/
    • 索引/
      • index.html
    • 布局/
      • main.html
  • index.php

index.php:

<?php
    $di = new Phalcon\DI\FactoryDefault();
    $di->set('volt', function ($view, $di){
        return new Phalcon\Mvc\View\Engine\Volt($view, $di);
    });

    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir("views/");
    $view->registerEngines(array(
        ".html" => 'volt'
    ));
    $view->setDi($di);
    $view->start();
    $view->render("index", 'index');
    $view->finish();
    echo $view->getContent();

views/index/index.html

{% extends "layouts/main.html" %}
{% block content %}
    <h2>Index</h2>
{% endblock %}

视图/布局/main.html

<h1>Main</h1>
{% block content %}
    Not index
{% endblock %}

当我运行php index.php 时,我得到:

未捕获的异常 'Phalcon\Mvc\View\Exception' 并带有消息“扩展 'layouts/main.html' 的模板视图不存在”

【问题讨论】:

    标签: php phalcon


    【解决方案1】:

    这是因为应用程序在实际路径中找不到文件main.html。如果添加完整路径,它可以工作,但是这样做很不方便。

    这样的事情会起作用

    {% extends  "../views/layouts/main.html" %}
    

    或者如果你的应用在app

    {% extends  "../app/views/layouts/main.html" %}
    

    我相信应该有一种方法可以直接从 Volt 的设置中引用根路径和/或视图路径。那很可能是 NFR。

    【讨论】:

    • 我理解的根目录应该是views文件夹。就像在 Twig 中一样。所以看起来像一个错误。
    猜你喜欢
    • 2013-03-20
    • 2021-07-15
    • 2013-06-19
    • 2014-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多