アプリ版:「スタンプのみでお礼する」機能のリリースについて

こんにちわ。
今SMARTYの勉強をしており、色々サンプルスクリプトを動かしたりしているのですが、PHPからHTML_QuickFormを動かす分には全く問題ないのですが(http://pear.php.net/manual/en/package.html.html- …のサンプルスクリプトは動作します)、テンプレート上で使おうと思うと動きません。SMARTYはインストールされていますし、HTML_QuickForm_Renderer_ArraySmartyの存在も確認しました。どこか設定する箇所があるのでしょうか?PEARとSMARTYの連携について書かれている書籍やサイトも少なく、苦戦しております。アドバイスの程よろしくお願いいたします。

A 回答 (3件)

>$form = new HTML_QuickForm();


>$form->addElement('text','name','Name');
>$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty);
>$form->accept($renderer);
>$smarty->assign('form',$renderer->toArray());
>$smarty = new Smarty();
>$smarty->display("2.tpl");
>?>

上記のプログラムでは、Smartyのインスタンス生成し、
HTML_QuickForm_Renderer_ArraySmartyに渡す
タイミングがおかしいのではないでしょうか?


$smarty = new Smarty();

HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->accept($renderer);
$smarty->assign('form',$renderer->toArray());

$smarty->display("2.tpl");
    • good
    • 0

もう解決してると思いますが。



$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty);

の$smartyはSmartyのインスタンスなので
先にインスタンスを生成しておく必要があります。

require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
require_once 'Smarty.class.php';

$smarty = new Smarty();

$form = new HTML_QuickForm();
$form->addElement('text','name','Name');
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->accept($renderer);
$smarty->assign('form',$renderer->toArray());

$smarty->display("2.tpl");
    • good
    • 0

どう動かないのか分かりませんが。



--- PHP ---
$form = new HTML_QuickForm();
$form->addElement('text','name','Name');
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->accept($renderer);
$smarty->assign('form',$renderer->toArray());

--- Smarty ---
{$form.name.html}

参考URL:http://www.is.titech.ac.jp/~yanagis0/kei/quickfo …

この回答への補足

早速の回答ありがとうございます。

ちょうど参考URLのスクリプトで試していたところでした。http://pear.php.net/manual/en/package.html.html- …の「Your first form」は動作しますので、HTML_QuickFormは問題ないのです。ですが、参考URLの「SMARTYとの連携」の部分がダメなんです。
回答頂きましたスクリプトを試してみたのですが、

-----2.php-----
<?php

require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
require_once 'Smarty.class.php';

$form = new HTML_QuickForm();
$form->addElement('text','name','Name');
$renderer =& new HTML_QuickForm_Renderer_ArraySmarty($smarty);
$form->accept($renderer);
$smarty->assign('form',$renderer->toArray());

$smarty = new Smarty();
$smarty->display("2.tpl");

?>

-----2.php-----
<html>
<head>
<title>TEST</title>
</head>
<body>
{$form.name.html}
</body>
</html>

どうもテンプレートすら呼び出していないようです。「$form = new HTML_QuickForm();」~「$smarty->assign('form',$renderer->toArray());」をコメントアウトしたら、テンプレートを呼び出しました。これは一体どういうことなのでしょうか。

補足日時:2006/07/15 10:04
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!