2012-08-02 52 views
0

我有一個文本元素聲明是這樣的:如何修飾文本元素標籤並分別輸入?

$name = $this->createElement('text', 'name'); 
$name->setLabel('imie:'); 

我想裝點這個元素來得到它呈現:

<div class="row"> 
    <span class="label"> 
    <label for="name" class="highlight">Name</label> 
    </span> 
    <span class="formw"> 
    <input type="text" id="someid" name="name" class="textfield"> 
    </span> 
</div> 

我不能設法得到它正常工作。 有人可以幫我設置裝飾器嗎?

回答

0

使用ViewScript裝飾:

部分@`意見/腳本/ _partial.phtml(命名爲你想要的)

<form action="<?php echo $this->element->getAction() ?>" 
     method="<?php echo $this->element->getMethod() ?>"> 
    <div class="row"> 
     <span class="label"> 
      <?php echo $this->element->name->renderLabel() //render the label for element ?> 
     </span> 
     <span class="formw"> 
      <?php echo $this->element->name->renderViewHelper() //render just the input of the element ?> 
     </span> 
     <?php echo $this->element->submit //render the whole submit element ?> 
    </div> 
</form> 

在表單設置裝飾:

class Application_Form_NewForm extends Zend_Form 
{ 
    public function init() { 
     $this->setMethod('POST'); 
     //set the viewscript decorator 
     $this->setDecorators(array(
      array('ViewScript', array(
        'viewScript' => '_partial.phtml' 
      )) 
     )); 
    //more follows... 

現在只是像往常一樣渲染你的表格

你可能有與元素裝飾器一起玩到你想要的東西,但這應該讓你接近你的目標。

希望這會有所幫助...

+0

感謝您的幫助。我現在正在工作。 – masteryoda 2012-08-02 10:53:26

+0

感謝您的幫助。我現在正在工作。 ('標籤',數組('標籤'=>'dt','class'=>'label'))我使用這個視圖腳本文件中的行來給出元素的類: element-> name-> addDecorator ;?> 和 element-> name-> class = @text; ?> 這是正確的方法嗎? – masteryoda 2012-08-02 11:00:18

+0

如果它有用,那麼我對這些裝飾者的理解就會有些微薄。不過,我會親自在窗體中修改這些修飾器,而不是在viewScript中進行修改。 – RockyFord 2012-08-02 11:39:17

相關問題