在苗条中使用时出现树枝错误
twig error when using in slim
您好,我需要将 twig 与 Slim 应用程序交互,我用 composer 安装了 twig,我已经有了我的脚本
<?php
use Slim\Slim;
use Slim\Views\Twig;
use Noodlehaus\Config;
use Codecourse\User\User;
session_cache_limiter(false);
session_start();
ini_set('display_errors','On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT.'/vendor/autoload.php';
$app = new Slim([
'mode' => file_get_contents(INC_ROOT.'/mode.php'),
'view' => new Twig(),
'template.path' => INC_ROOT . '/app/views'
]);
$app->view->setTemplatesDirectory("/views");
$app->configureMode($app->config('mode'), function() use ($app) {
$app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
});
echo $app->config->get('db.driver');
require 'database.php';
$app->container->set('user', function() {
return new User;
});
$app->get('/', function() use ($app) {
$app->render('home.php');
});
当我 运行 编写脚本时出现此错误:
Type: Twig_Error_Loader
Message: The "/views" directory does not exist.
File:
C:\xampp\htdocs\authentication\vendor\twig\twig\lib\Twig\Loader\Filesystem.php
Slim documentation for configuring the template path 可能有点误导;您只需要设置 template.path
或调用 View::setTemplatesDirectory
但不需要同时设置。
如果您想使用后者,则只需:
$app->view->setTemplatesDirectory(INC_ROOT . '/app/views');
我的愚蠢错误
我必须使用
'templates.path' => INC_ROOT . '/app/views'
我有
'template.path' => INC_ROOT . '/app/views'
您好,我需要将 twig 与 Slim 应用程序交互,我用 composer 安装了 twig,我已经有了我的脚本
<?php
use Slim\Slim;
use Slim\Views\Twig;
use Noodlehaus\Config;
use Codecourse\User\User;
session_cache_limiter(false);
session_start();
ini_set('display_errors','On');
define('INC_ROOT', dirname(__DIR__));
require INC_ROOT.'/vendor/autoload.php';
$app = new Slim([
'mode' => file_get_contents(INC_ROOT.'/mode.php'),
'view' => new Twig(),
'template.path' => INC_ROOT . '/app/views'
]);
$app->view->setTemplatesDirectory("/views");
$app->configureMode($app->config('mode'), function() use ($app) {
$app->config = Config::load(INC_ROOT . "/app/config/{$app->mode}.php");
});
echo $app->config->get('db.driver');
require 'database.php';
$app->container->set('user', function() {
return new User;
});
$app->get('/', function() use ($app) {
$app->render('home.php');
});
当我 运行 编写脚本时出现此错误:
Type: Twig_Error_Loader
Message: The "/views" directory does not exist.
File: C:\xampp\htdocs\authentication\vendor\twig\twig\lib\Twig\Loader\Filesystem.php
Slim documentation for configuring the template path 可能有点误导;您只需要设置 template.path
或调用 View::setTemplatesDirectory
但不需要同时设置。
如果您想使用后者,则只需:
$app->view->setTemplatesDirectory(INC_ROOT . '/app/views');
我的愚蠢错误
我必须使用
'templates.path' => INC_ROOT . '/app/views'
我有
'template.path' => INC_ROOT . '/app/views'