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

FuelPHP【parser】デフォルトのviewの拡張子が.phpだとみずらいので識別拡張子を変更する

More than 5 years have passed since last update.

テンプレートエンジンって書きづらくないですか?
書きづらくない。そうですか。
自分は素のPHPがすきなんですがFuel\Coew\Viewの拡張子が.phpだとvimとかでタブをいっぱい開いたときにどれがcontrollerでどれがviewかがわかりずらいのでいっそのこと拡張子を変更することにしました。

環境

  • centos6.3
  • fuelPHP1.6.1

事前準備に必要なもの

参考にしたサイト

packages/parser/config/perser.phpをコピーする

cp fuel/packages/parser/parser.php fuel/app/config/

編集

fuel/app/config/parser.php
return array(

    // ------------------------------------------------------------------------
    // Register extensions to their parsers, either classname or array config
    // ------------------------------------------------------------------------
    'extensions' => array(
        'phtml'     => 'View',
    ),
);

1.5系とかは適時packagesのパスを置き換えてください。

packageのロード

fuel/app/config/config.php
    'always_load'  => array(
        'packages'  => array(
            'parser',
           'my',
        ),

Fuel\Core\Viewを継承したクラスを作成する

ファイルの置き場所は好みに応じて自分は自分用パッケージ作って管理しました。

mkdir fuel/packages/my fuel/packages/classes fuel/packages/my/config fuel/packages/my/tests 

bootstrap.phpを置く

fuel/packages/my/bootstrap.php
<?php
Autoloader::add_core_namespace('My');

Autoloader::add_classes(array(
    'My\\View'                         => __DIR__.'/classes/view.php',
));


/* End of file bootstrap.php */

拡張viewクラス

fuel/packages/my/clasees/view.php
<?php
namespace My;


/**
 * View class
 *
 * Acts as an object wrapper for HTML pages with embedded PHP, called "views".
 * Variables can be assigned with the view object and referenced locally within
 * the view.
 *
 * @package   My
 * @category  View
 */
class View extends \Fuel\Core\View
{
    /**
     * @var  string  The view file extension
     */
    protected $extension = 'phtml';
}

$extensionはお好みに応じて変更すればと

上記の設定が完了したらviewsのファイルの拡張子を変更すればできあがりです。

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
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