Help us understand the problem. What is going on with this article?

FuelPHP1.7.3のテンプレートエンジンにsmartyを設定

More than 3 years have passed since last update.

FuelPHP1.7.3でsmarty3系を使えるようにした。

1.composer.jsonの修正

requireの箇所にsmartyの記述を追記する。

composer.json
"require": {
        "php": ">=5.3.3",
        "composer/installers": "~1.0",
        "fuel/docs": "dev-1.7/master",
        "fuel/core": "dev-1.7/master",
        "fuel/auth": "dev-1.7/master",
        "fuel/email": "dev-1.7/master",
        "fuel/oil": "dev-1.7/master",
        "fuel/orm": "dev-1.7/master",
        "fuel/parser": "dev-1.7/master",
        "fuelphp/upload": "2.0.2",
        "monolog/monolog": "1.5.*",
        "michelf/php-markdown": "1.4.0",
        "smarty/smarty": "3.*"
    },

2.composerの依存ライブラリをupdate

composer.jsonの修正を反映させる。

$ php composer.phar update

3.Parserパッケージを有効にする

fuel/app/config/config.phpを修正する。(always_loadの箇所)

config.php
    /**************************************************************************/
    /* Always Load                                                            */
    /**************************************************************************/
    'always_load'  => array(

        /**
         * These packages are loaded on Fuel's startup.
         * You can specify them in the following manner:
         *
         * array('auth'); // This will assume the packages are in PKGPATH
         *
         * // Use this format to specify the path to the package explicitly
         * array(
         *     array('auth' => PKGPATH.'auth/')
         * );
         */
         'packages'  => array(
            //'orm',
            'parser',
         ),

4.parser.phpの修正

fuel/packages/parser/config/parser.phpを修正する。
View_SmartyincludeのKEYを追記する。

parser.php
// SMARTY ( http://www.smarty.net/documentation )
    // ------------------------------------------------------------------------
    'View_Smarty' => array(
        'include' => APPPATH.'vendor'.DS.'smarty'.DS.'libs'.DS.'Smarty.class.php',
        'auto_encode' => true,
        'delimiters'  => array('left' => '{', 'right' => '}'),
        'environment' => array(
            'compile_dir'       => APPPATH.'tmp'.DS.'Smarty'.DS.'templates_c'.DS,
            'config_dir'        => APPPATH.'tmp'.DS.'Smarty'.DS.'configs'.DS,
            'cache_dir'         => APPPATH.'cache'.DS.'Smarty'.DS,
            'plugins_dir'       => array(),
            'caching'           => false,
            'cache_lifetime'    => 0,
            'force_compile'     => false,
            'compile_check'     => true,
            'debugging'         => false,
            'autoload_filters'  => array(),
            'default_modifiers' => array(),
        ),
    ),

5.templates_cなどのフォルダ作成

smartyでコンパイル後のファイルを格納するフォルダなど3つ作成。
3つともパーミッションは777に。

fuel/app/tmp/Smarty/configs
fuel/app/tmp/Smarty/templates_c
fuel/app/cache/Smarty

6.コントローラからビューの呼び出し例

controller

fuel/app/classes/controller/welcome.php
/**
     * The test action for the application.
     *
     * @access  public
     * @return  Response
     */
    public function action_test()
    {
        $t_params = array(
            'message' => 'smarty template テスト'
        );
        $view = View::forge('welcome/test.html');
        $view->title = 'テスト!';
        $view->username = '太郎';
        return $view;
    }

template

fuel/app/views/welcome/test.html
test.html
{$title}{$username}

7.表示

Compile Error!

エラーです。
以下の対応をしたら直りました。

view.phpの修正

fuel/packages/parser/classes/view.phpを修正する。
正しい対応かはわからないが、38行目,89行目のrequire $include;をコメントアウトする。
これで動くようになった。

参考

FuelPHP 1.7でのSmartyのセットアップ
Fuelphp : class ‘smarty’ not found
FuelPHPのコントローラからビューへ変数を渡す

tageo
よろしくお願いします。
http://www.tageo.net
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした