2012-09-27 32 views

回答

1

是!
viewScript Decorator是你的朋友。

//the viewScript 
<article class="login"> 
    <form action="<?php echo $this->element->getAction() ?>" 
      method="<?php echo $this->element->getMethod() ?>"> 
     <table> 
      <tr> 
       <th>Login</th> 
      <tr> 
       //renders just the Label decorator 
       <td><?php echo $this->element->name->renderLabel() ?></td> 
       //renders just the viewHelper decorator 
       <td><?php echo $this->element->name->renderViewHelper() ?></td> 
      </tr> 
      <tr> 
       //renders just the Label decorator 
       <td><?php echo $this->element->password->renderLabel() ?></td> 
       //renders just the viewHelper decorator 
       <td><?php echo $this->element->password->renderViewHelper() ?></td> 
      </tr> 
      <tr> 
       //renders the entire element 
       <td><?php echo $this->element->submit ?></td> 
      </tr> 
     </table> 
    </form> 
</article> 

表单

<?php 
class Application_Form_Login extends Zend_Form 
{ 

    public function init() { 
     $this->setMethod('POST'); 
     $this->setAction('/index/login'); 

     /** 
     * Set the viewScript decorator 
     */ 
     $this->setDecorators(array(
      array('ViewScript', array(
        'viewScript' => '_login.phtml' 
      )) 
     )); 

     /** 
     * Text element 'name' 
     */ 
     $name = new Zend_Form_Element_Text('name'); 
     $name->setLabel('Name'); 
     $name->setAttrib('placeholder', 'Username'); 
     $name->setOptions(array('size' => 20)); 

     /** 
     * Password element for 'password' 
     */ 
     $password = new Zend_Form_Element_Password('password'); 
     $password->setLabel('Password'); 
     $password->setAttrib('placeholder', 'Password'); 
     $password->setOptions(array('size' => 20)); 

     $submit = new Zend_Form_Element_Submit('submit'); 
     $submit->setLabel('Login'); 

     $this->addElements(array($name, $password, $submit)); 
    } 
} 

希望这有助于。