HTML_QuickFormのみではしっかり表示され検証も動作しますが…Smartyのテンプレートを使用した場合QuickForm以前のHTMLとPHPだけ表示がされ、テンプレートの呼び出しができず、それ以降のHTMLも表示されません。タグもそれ以前で切れてしまっています。
問題のスクリプトはこちらから、参照ください。⇒http://kinsekitei.com/prototype/sample.html
きっとテンプレートファイルの呼び出しとテンプレートファイル自体の記述が上手くいっていないと思われます。
どなたかご存知の方が居ましたら…ご教授ください。よろしくお願いします。
以下のパスとパーミッションは合っていますか?
この部分をフルパスで記述する例はあまり見かけないものですから、確認してください。
$smarty->template_dir = '/var/www/vhosts/kinsekitei.com/httpdocs/smarty/templates'; $smarty->compile_dir = '/var/www/vhosts/kinsekitei.com/httpdocs/smarty/templates_c/'; $smarty->config_dir = '/var/www/vhosts/kinsekitei.com/httpdocs/smarty/configs/'; $smarty->cache_dir = '/var/www/vhosts/kinsekitei.com/httpdocs/smarty/cache/';
コメント(8件)
基本的な問題で「Smarty.class.php」ライブラリーが呼べていないようです…php.iniにてinclude_pathや、require_onceにて絶対パスを用いて動作確認用のサンプルで試してみても反応しません。/usr/local/lib/Smarty-3.1.1/左記のディレクトリー「Smarty-3.1.1」を⇒「Smarty」に変更すべきなのでしょうか?
ちなみにSmarty.class.phpのパーミッションも644で大丈夫なのでしょうか?
基本的な質問で、大変申し訳ありませんが、ご教授いただけると助かります。
よろしくお願いします。
前回の追記1のライブラリの読み込みの確認はクリアできました。ですが、基本的なレンダリングの問題はクリアできていません。。。
HTML_QuickFormだけでの表示ソースを確認したところ…<form>タグの前でSubmitからのJavascriptが展開していました。その事を踏まえて、form.tplの記述を試行錯誤してみましたが…達成できませんでした。テンプレートに<script>{$form.javascript}</script>と記述しても動作しません。
どなたか、ご教授いただけると助かります。
----------------------------------------------------
<*QuickFormのみで表示したPHPファイルでは、この直前部分でJavaScriptが展開>
<form {$form.attributes} >
{$form.hidden.prod_id}{$form.hidden.info_id}
{$form.number.label}{$form.number.error}{$form.number.html}{$form.Submit.html}
</form>
------------------------------------------------------
現在のファイルの記述したファイルはこちらになります。
↓↓↓↓
http://kinsekitei.com/prototype/sample.html
お手数かけますが…ご教授のほど、よろしくお願いいたします。
<< error >>
Fatal error: Uncaught exception 'SmartyException' with message 'unable to write file /var/www/vhosts/kinsekitei.com/httpdocs/smarty/templates_c/wrt4e7faecf37433' in /usr/local/lib/smarty/libs/sysplugins/smarty_internal_write_file.php:46 Stack trace: #0 /usr/local/lib/smarty/libs/sysplugins/smarty_internal_template.php(199): Smarty_Internal_Write_File::writeFile('/var/www/vhosts...', '<?php /* Smarty...', Object(Smarty)) #1 /usr/local/lib/smarty/libs/sysplugins/smarty_internal_templatebase.php(147): Smarty_Internal_Template->compileTemplateSource() #2 /usr/local/lib/smarty/libs/sysplugins/smarty_internal_templatebase.php(348): Smarty_Internal_TemplateBase->fetch('/var/www/vhosts...', NULL, NULL, NULL, true) #3 /var/www/vhosts/kinsekitei.com/httpdocs/stone/agate/agate_b001.php(191): Smarty_Internal_TemplateBase->display('/var/www/vhosts...') #4 {main} thrown in /usr/local/lib/smarty/libs/sysplugins/smarty_internal_write_file.php on line
--------------------------------------------------------------------
パ
スを確認してみました。絶対パスは合っていました…
相対パスでの記述は、
$smarty->template_dir ='./templates/' でよろしいのでしょうか?
Fatal error: Uncaught exception 'SmartyException' with message 'unable to write file /var/www/vhosts/kinsekitei.com/httpdocs/smarty/templates_c/...
のエラーが出てしまっています。解決方法をご存知の方がいましたら、ご教授ください。よろしくお願いします。
$smarty->compile_dir = '/~フルパス~/templates_c/';
$smarty->config_dir = '/~フルパス~/configs/';
$smarty->cache_dir= '/~フルパス~/cache/';
$smarty->display('/~フルパス~/form.tpl');
フルパスで記述とパーミッション777設定で解決できました。
ご指導、ありがとうございました。
その必要はありません。
define('SMARTY_DIR','/usr/local/lib/smarty/libs/');
のパスが通ればいいだけです。「Smarty-3.1.1」なら
define('SMARTY_DIR','/usr/local/lib/Smarty-3.1.1/libs/');
となります。
>Smarty.class.phpのパーミッションも644で大丈夫なのでしょうか?
大丈夫です。
>相対パスでの記述は、
>$smarty->template_dir ='./templates/' でよろしいのでしょうか?
相対パスは最初にアクセスされるファイルの位置からの相対ですのでやり方によっては面倒です。
よいかどうかはどう配置しているかによります。デフォルトは./templates/です。
>相対パスで$smarty->template_dir ='./templates/と記述し、
>/templates_c/と/cache/のパーミッションを770としましたが…
オーナーとパーミッションを設定することで解決するかもしれません。
http://www.gadgety.net/shin/tips/unix/php-tmpl.html
それも解決しないなら777とする方法もあります。
公開デレクトリーに777としたデレクトリーがあるのはまずいので再配置する必要があるでしょう。
/var/www/vhosts/kinsekitei.com/httpdocsが公開デレクトリー(DocumentRoot)なら
/var/www/vhosts/kinsekitei.com/smarty/templates_c/や
/var/www/vhosts/kinsekitei.com/templates_c/とします。
アクセスが
http://kinsekitei.com/prototype/sample.phpなら
/var/www/vhosts/kinsekitei.com/httpdocs/prototype/sample.phpとなり
sample.phpからは
$smarty->template_dir ='../../smarty/templates/'や
$smarty->template_dir ='../../templates/'となるでしょう。
相対位置をいちいち確認するのが面倒だというのなら
define('SMARTY_WORK_DIR', '/var/www/vhosts/kinsekitei.com/smarty/');
$smarty->template_dir = SMARTY_WORK_DIR . 'templates/';
のような書き方をすると便利でしょう。(SMARTYという名前を使うのは問題かも)
var_dump($renderer->toArray());
とすればどのような名前が使われているか確認できます。
それによるとform.tplの
{$form.hidden.prod_id}
{$form.hidden.info_id}
は
{$form.hidden}
とする必要があります。
$smarty->display('/var/www/vhosts/kinsekitei.com/httpdocs/smarty/templates/form.tpl');
は
$smarty->display('form.tpl');
でいいはずです。
現在のサンプルファイル→ http://kinsekitei.com/prototype/sample.html