統合がうまくいきます。しかし、テンプレート文字列のxgettextと統合しようとすると、致命的なエラーが発生します。私はテンプレートを "The i18n Extension"と小枝に統合しようとしています。 xgettextとの統合に固執する
Fatal error: Uncaught Twig_Error_Loader: Unable to find template "C:/MAMP/htdocs/views/site/blocks/contactform.html" (looked into: C:\MAMP\htdocs/views/site). in C:\MAMP\htdocs\components\twig\Loader\Filesystem.php:232 Stack trace: 0 C:\MAMP\htdocs\components\twig\Loader\Filesystem.php(150): Twig_Loader_Filesystem->findTemplate('C:/MAMP/htdocs/...') #1 C:\MAMP\htdocs\components\twig\Environment.php(329): Twig_Loader_Filesystem->getCacheKey('C:\MAMP\htdocs/...') #2 C:\MAMP\htdocs\components\twig\Environment.php(419): Twig_Environment->getTemplateClass('C:\MAMP\htdocs/...') #3 C:\MAMP\htdocs\controllers\mainController.php(43): Twig_Environment->loadTemplate('C:\MAMP\htdocs/...') #4 C:\MAMP\htdocs\controllers\siteController.php(22): mainController->loadTwig() #5 C:\MAMP\htdocs\components\router.php(83): siteController->actionIndex() #6 C:\MAMP\htdocs\index.php(12): Router->Run() #7 {main} thrown in C:\MAMP\htdocs\components\twig\Loader\Filesystem.php on line 232
そしてここでは私のコードでエラーがあります:
class mainController {
var $twig = null;
public $configs;
public $langlibrary;
const DEFAULT_LANGUAGE = 'en';
public function __construct() {
$this->configs = Config::getConfigiration();
}
public function loadTwig() {
require_once 'components/Twig/Autoloader.php';
Twig_Autoloader::register();
$tplDir = ROOT.'/views/site';
$tmpDir = 'cache';
$loader = new Twig_Loader_Filesystem($tplDir);
$this->twig = new Twig_Environment($loader, array(
'cache' => $tmpDir,
'auto_reload' => true
));
$this->twig->addExtension(new Twig_Extensions_Extension_I18n());
// THE PROBLEM BEGINS WHEN ADD CODE BELOW FOR INETGRATION
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file)
{
// force compilation
if ($file->isFile()) {
$this->twig->loadTemplate(str_replace($tplDir.'/', '', $file));
}
}
atmを実行しているように、絶対パスではなく相対パスを渡す必要があります。 ( 'C:\ ......... \ blocks \ contactform.html'ではなく' blocks/contactform.html') – DarkBee