通常、EC-CUBEでSmartyのデバッグコンソールを表示させたい場合、
管理画面 ⇒ システム設定 ⇒ パラメータ設定 ⇒ 「DEBUG_MODE」をtrueにし、
tplファイルに
<!--{debug}-->を追加すると、デバッグコンソールが表示されます。
//html内容に表示したい時はこれ <!--{debug output='html'}--> //ポップアップはこれでもOK <!--{debug output=''}-->
ただ、途中の$objDisplayの行にくるとどうしても
エラーメッセージを吐いて止まってしまいます。
メッセージ:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 377434 bytes) in /data/module/Smarty/libs/plugins/modifier.debug_print_var.php on line 37
エラー文言を読む限りは、メモリをオーバーをしているという事だと思い
php.iniの「memory_limit」を変更したのですが直りませんでした。
色々確認したのですが全くわからなくて途方にくれていたら、
以下の記事をみつけて解決できました。
——————————————–
デバッグコンソールの中で、オブジェクトのプロパティを列挙する際に、
オブジェクトを発見すると再帰呼び出しが起こるのだが、
再帰の階層を制限していないので、オブジェクトが相互参照していると
無限ループ化するようだ。
——————————————–
Smartyを使っていてApacheが落ちた: Zefard’s Labo より記事転載
おお~、そういう事か~と思い、以下のファイルを修正しました。
/data/module/Smarty/libs/plugins/modifier.debug_print_var.php
function smarty_modifier_debug_print_var($var, $depth = 0, $length = 40) { $_replace = array( "\n" => '<i>\n</i>', "\r" => '<i>\r</i>', "\t" => '<i>\t</i>' ); //この行を追加 if ($depth > 10) return ''; switch (gettype($var)) {
たぶん表示できてるはずです。
悩みの種の$objDisplayを確認すると、これはかなり長い。
特に必要もないかな~と思われるので、今回は「debug.tpl」で対応する事にします。
/data/module/Smarty/libs/debug.tpl
{* Smarty *} {* debug.tpl, last updated version 2.1.0 *} {assign_debug_info} {capture assign=debug_output} <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Smarty Debug Console</title> {literal} <style type="text/css"> /* <![CDATA[ */ .exectime { font-size: 0.8em; font-style: italic; } #table_assigned_vars th { color: blue; } #table_config_vars th { color: maroon; } //スタイル追加 table { margin: 15px auto 20px auto; border-top: 1px solid #ccc; border-left: 1px solid #ccc; width: 100%; border-collapse: collapse; text-align: left; } table th { padding: 8px; border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; color: #333; background-color: #f0f0f0; font-weight: normal; } table td { padding: 8px; border-right: 1px solid #ccc; border-bottom: 1px solid #ccc; } /* ]]> */ </style> {/literal} </head> <body> <h1>Smarty Debug Console</h1> <h2>included templates & config files (load time in seconds)</h2> <div> {section name=templates loop=$_debug_tpls} {section name=indent loop=$_debug_tpls[templates].depth} {/section} <font color={if $_debug_tpls[templates].type eq "template"}brown{elseif $_debug_tpls[templates].type eq "insert"}black{else}green{/if}> {$_debug_tpls[templates].filename|escape:html}</font> {if isset($_debug_tpls[templates].exec_time|smarty:nodefaults)} <span class="exectime"> ({$_debug_tpls[templates].exec_time|string_format:"%.5f"}) {if %templates.index% eq 0}(total){/if} </span> {/if} <br /> {sectionelse} <p>no templates included</p> {/section} </div> <h2>assigned template variables</h2> <table id="table_assigned_vars"> {section name=vars loop=$_debug_keys} //if文追加 {if $_debug_keys[vars] != 'objDisplay'} <tr class="{cycle values="odd,even"}"> <th>{ldelim}${$_debug_keys[vars]|escape:'html'}{rdelim}</th> <td>{$_debug_vals[vars]|@debug_print_var}</td></tr> {/if} //if文おわり {sectionelse} <tr><td><p>no template variables assigned</p></td></tr> {/section} </table> <h2>assigned config file variables (outer template scope)</h2> <table id="table_config_vars"> {section name=config_vars loop=$_debug_config_keys} <tr class="{cycle values="odd,even"}"> <th>{ldelim}#{$_debug_config_keys[config_vars]|escape:'html'}#{rdelim}</th> <td>{$_debug_config_vals[config_vars]|@debug_print_var}</td></tr> {sectionelse} <tr><td><p>no config vars assigned</p></td></tr> {/section} </table> </body> </html> {/capture} {if isset($_smarty_debug_output|smarty:nodefaults) and $_smarty_debug_output eq "html"} {$debug_output} {else} <script type="text/javascript"> // <![CDATA[ if ( self.name == '' ) {ldelim} var title = 'Console'; {rdelim} else {ldelim} var title = 'Console_' + self.name; {rdelim} //Chrome対策 {literal}title = {value : 'dummy'};{/literal} _smarty_console = window.open("",title.value,"width=680,height=600,resizable,scrollbars=yes"); _smarty_console.document.write('{$debug_output|escape:'javascript'}'); _smarty_console.document.close(); // ]]> </script> {/if}
詳しくは差分で見て頂きたいのですが、
if文で【$_debug_keys[vars]】が【objDisplay】で表示しないように制御しています。
その他に
・ポップアップした時のレイアウトを若干修正。
・ついでにChromeのブラウザを使用してポップアップの場合、更新する度に新しいウィンドウが開いて大変なのでJavascriptのコードに1行追加も対応してます。
やっとできた。。。
⇒14)この商品について問い合わせをする-hetemlのサーバでEC-CUBE(2.11.4)を使ってみる
⇒hetemlのサーバでEC-CUBEインストール~公開までの道のり