LoginSignup
9
3

More than 3 years have passed since last update.

EC-CUBE3でデバッグモードを利用する手順【index_dev.php不要】

Last updated at Posted at 2019-05-21

先日ECCUBE3で構築されているサイトを触ることになったのですが、

  • index_dev.php が無い!?
  • dump()が使えない(本番環境と同じ設定になっている?)
  • Warningエラーが既存で大量発生していてローカル環境が見れない

というめまいの催すような環境だったのでデバッグモード設定の手順をまとめます。

ECCUBE3を触るときにindex_dev.phpを付けてデバッグするのが一般的だと思いますが、
毎回URL打つのは手間なので、URL変える必要なくデバッグモードを設定していきます。

デバッグモードを設定する手順

ECCUBEのconfig.ymlを修正

デバッグモードをconfigで設定できるようにします。

app/config/eccube/config.yml
auth_magic: xxxxx
password_hash_algos: sha256
shop_name: the_shop
force_ssl: 1
admin_allow_host: {  }
cookie_lifetime: 0
locale: ja
timezone: Asia/Tokyo
eccube_install: 1
option_favorite_product: 0
+ debug: true

Application側でconfigを読み込み

yamlで設定した値を読み、config: trueであればsymfonyのデバッグハンドラーを呼び出しています。
Application.phpのinitialize()メソッドであればどこに記載してもよいかと思います。

src/Eccube/Application.php
    public function initialize()
    {
    //
    // ...
    //
+    if (isset($this['config']['debug']) && $this['config']['debug']) {
+      $this['debug'] = true;
+      Debug::enable(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_WARNING);
+    }

TwigServiceProviderの設定変更

これまででデバッグモード自体は有効になりましたが、
Twig上で発生している既存のNoticeやWarningエラーを無視したいので下記を設定します。

vendor/silex/silex/src/Silex/Provider/TwigServiceProvider.php
/**
 * Twig integration for Silex.
 *
 * @author Fabien Potencier <fabien@symfony.com>
 */

class TwigServiceProvider implements ServiceProviderInterface
{
    public function register(Application $app)
    {
        $app['twig.options'] = array();
        $app['twig.form.templates'] = array('form_div_layout.html.twig');
        $app['twig.path'] = array();
        $app['twig.templates'] = array();

        $app['twig'] = $app->share(function ($app) {
            $app['twig.options'] = array_replace(
                array(
                    'charset' => $app['charset'],
                    'debug' => $app['debug'],
-                    'strict_variables' => $app['debug'],
+                    'strict_variables' => false,
                ), $app['twig.options']
            );


これでURLを切り替えることなくデバッグモードが使えるようになりました!

Image201905201138.png

ECCUBE3のデバッグで困っている..という方は試してみてはどうでしょうか。

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