2014-07-10 42 views
-4

我有這樣的代碼`我怎麼能寫HTML代碼的Zend框架

 <div class="input-prepend"> 
      <span class="add-on"><i class="icon-user"></i></span> 
      <input type="text" placeholder="Username"> 
     </div> 

     <div class="input-prepend"> 

      <span class="add-on"><i class="icon-lock"></i></span> 
      <input type="password" placeholder="Password"> 
      <a href="index.html"><span class="add-on" id="login"><i class="icon-arrow-right"></i></span></a> 

     </div> 

,我想對Zend框架文件的一個.phtml我與MVC 工作,可你寫的請幫我我怎麼可以寫在文件.phtml在zend框架 所以我用這個<?php echo $this->element->loginAd->renderViewHelper(); ?>,我不知道我怎麼做<span class="add-on"> <i class="icon-user"></i> </span> Syntaxe相同的zend視圖 我想做的主題相同的HTML/CSS 當我寫這個代碼

`<form class="form-signin" name="login-form" id="login-form" method="<?php echo $this->escape($this->element->getMethod()); ?>" action="<?php echo $this->escape($this->element->getAction()); ?>"> 
      <h2 class="form-signin-headin 

g"><strong>Administration</strong></h2> 
      <div class="input-prepend"> 
       <span class="add-on"> 
       <i class="icon-user"></i> 
       </span> 

       <?php echo $this->element->loginAd->renderViewHelper(); ?> 
      </div> 
      <div class="input-prepend"> 
       <span class="add-on"><i class="icon-lock"></i></span> 
       <?php echo $this->element->password->renderViewHelper(); ?> 
       <a href="index.html"><span class="add-on" id="login"><i class="icon-arrow-right"></i></span></a> 
      </div> 

      <?php echo $this->element->submit->renderViewHelper(); ?> 
      <p class="input-height"> 
       <input type="checkbox" name="keep-logged" id="keep-logged" value="1" class="mini-switch" checked="checked"> 
       <label for="keep-logged" class="inline"><?=$this->translate('Stay connected');?></label> 
      </p> 
     </form>` 

感謝您的幫助很大

回答

0

您需要按照以下步驟 1.創建一個表單

namespace Application\Form; 

use Zend\Form\Form; 
use Zend\Db\Adapter\AdapterInterface; 
use Zend\Db\Adapter\Adapter; 
class UserForm extends Form 
{ 
    public function __construct() 

    { 
     parent::__construct('usser'); 
     $this->setAttribute('method', 'post'); 

     $this->addElement(
      'text', 'username', array(
       'label' => 'Username:', 
       'required' => true, 
       'filters' => array('StringTrim'), 
      )); 

     $this->addElement('password', 'password', array(
      'label' => 'Password:', 
      'required' => true, 
      )); 

     $this->addElement('submit', 'submit', array(
      'ignore' => true, 
      'label' => 'Login', 
      )); 

    } 
} 

2實例化在控制器或工廠形成什麼永遠是最好的 你

public function indexAction(){ 
    $form = new UserForm($dbAdapter); 
     return array('form'=>$form); 

} 
    在視圖腳本
  1. index.phtml
<?php 
$title = 'New Admin User '; 
$this->headTitle($title); 
?> 
<h1><?php echo $this->escapeHtml($title); ?></h1> 
<?php 
$form = $this->form; 
$form->setAttribute('action', $this->url('user', array('action' => 'index'))); 
$form->prepare(); 

echo $this->form()->openTag($form); 

foreach ($form as $element) { ?> 

<?php 
echo $this->formRow($element); ?> 



<?php }?> 
<?php 
echo $this->form()->closeTag(); 
+0

謝謝你的回答,但我有我想要做的代碼''?php echo $ this-> element-> loginAd-> renderViewHelper(); ?>'我如何編寫'<跨度類= 「附加」> \t \t \t \t \t \t \t \t' – user3791255

0

你可以只使用完全相同的HTML代碼,只是更換輸入

<?php echo $this->formElement($form->get('name')) ?> 

一個完整的例子是:

<?php echo $this->form()->openTag($form) ?> 
<div class="form-group"> 
    <?php echo $this->formLabel($form->get('name')); ?> 
    <?php echo $this->formElement($form->get('name')); ?> 
</div> 
<?php echo $this->form()->closeTag($form) ?> 

有關佔位符,請參閱amarjit sngh解決方案。