2011-01-15 9 views
0

でZendのフォーム要素をレンダリングすることができません:私はレンダリングするとき私はこのようなLogin.phpフォーム持ってViewScript

<table> 
    <tr> 
     <td><?= $this->getElement('username') ?></td> 
    </tr> 
    <tr> 
     <td><?= $this->getElement('password') ?></td> 
    </tr> 

</table> 

/authentication/login-form.phtml

class Form_Login extends Zend_Form { 

    public function init() { 
    } 

    public function __construct(){ 

     // Set method 
     $this->setMethod('post'); 

     $elements = array(); 

     $element = $this->createElement('text','username'); 
     $element->setRequired(true); 
     $elements[] = $element; 

     $element = $this->createElement('password','password'); 
     $element->setRequired(true); 
     $elements[] = $element; 

     $this->addElements($elements); 

     $this->setDecorators(array(array('viewScript', array('viewScript' => '/authentication/login-form.phtml')))); 
    } 
} 

をフォームを入力すると、次の例外が発生します。

Message: Plugin by name 'GetElement' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/;C:/wamp/www/databox/application/views\helpers/ 

私は間違っている。 application.iniまたはBootstrapに情報を入力する必要があります。

ありがとうございます。

答えて

3

フォームを動作させるには、ビュースクリプトにフォームを渡す必要があります。あなたのビュースクリプトで

public function someAction() 
{ 
    $this->view->form = new Form_Login(); 
} 

あなたは

<table> 
<tr> 
    <td><?= $this->form->getElement('username'); ?></td> 
</tr> 
<tr> 
    <td><?= $this->form->getElement('password'); ?></td> 
</tr> 
</table> 
+0

はい、私はsomeActionで同じことをやっているし、フォームをレンダリング** some.phtml **は '$ this-> form-> render();'のようです。しかし、フォーム要素は** login-form.phtml **で表示されるべきだと思います。 – Awan

+0

あなたは、ログインフォームがレンダリングされる関連アクションのないビュースクリプトを持っていますか? –

+0

@Samuel Herzog:私はこれについて知らないし、初めてZendフォームに取り組んでいます。もっと説明してください。ありがとうございました – Awan

1
$this->setDecorators(array(array('viewScript', array('viewScript' =>'/authentication/login-form.phtml','form'=>$form)))); 

を経由して要素を受信することができ、その後、ビューに

$this->form->getElement('elementName'); 
関連する問題