繁体   English   中英

使用伏特与phalcon有问题

[英]Have problems with using Volt with phalcon

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

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();

视图/索引/ 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'不存在'

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

这样的东西会起作用

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

或者如果您的应用程序在app

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM