7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

FuelPHP1.6のComposerを使用してTwigを有効にする方法

Posted at

FuelPHPの1.6に付属してくるcomposer.jsonを使ってTwigを利用しようとすると、そのままでは使用出来なくて困ったので書いておく。
キモはparser.phpのinclude指定だった。

#1. Twigのインストール

##require部分にtwigの設定を追加する

composer.json
{
    "require": {
        "php": ">=5.3.3",
        "monolog/monolog": "1.5.*",
    	"fuelphp/upload": "2.0",
        "twig/twig": "1.13.0"
    }
}

##composerでインストールする

php composer.phar install

#2. Twigを有効にする

##設定を修正する

fuel/app/config/config.php

config.php
return array(
    'always_load' => array(
        'packages'  => array(
            'parser',
        ),
    ),
);

##parserパッケージの使用準備を行う
fuel/packages/parser/config/parser.phpをfuel/app/config/ にコピーする

fuel/app/config/parser.php

parser.php
return array(
    'extensions' => array(
        'twig' => 'View_Twig',
    ),
    'View_Twig' => array(
         'include' => dirname(APPPATH) . DS . 'vendor' . DS . 'twig' . DS . 'twig' . DS . 'lib' . DS . 'Twig' . DS . 'Autoloader.php',
    ),
);

#3. コントローラからtwigのビューを呼び出す

hoge.php
class Controller_Hoge extends Controller
{
    public function action_index()
    {
        return \Response::forge(\View::forge('hoge/index.twig'));
    }
}
7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?