【问题标题】:How can i write the html code on Zend Framework我如何在 Zend Framework 上编写 html 代码
【发布时间】:2014-07-10 16:16:51
【问题描述】:

我有这个代码`

他们
        <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>

我想在我使用 MVC 的 zend 框架上写文件 .phtml 你能帮我吗?我怎样才能在zend框架上的文件.phtml上写它 所以我使用这个&lt;?php echo $this-&gt;element-&gt;loginAd-&gt;renderViewHelper(); ?&gt;,我不知道我是怎么做到的<span class="add-on"> <i class="icon-user"></i> </span>in Syntxe 与 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>`

感谢您的大力帮助

【问题讨论】:

    标签: css html zend-framework php


    【解决方案1】:

    您需要按照以下步骤操作 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();
    

    【讨论】:

    • 谢谢你的回答,但我有我想做的代码&lt;?php echo $this-&gt;element-&gt;loginAd-&gt;renderViewHelper(); ?&gt;我怎么写&lt;span class="add-on"&gt; &lt;i class="icon-user"&gt;&lt;/i&gt; &lt;/span&gt;
    【解决方案2】:

    您可以使用完全相同的 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 解决方案。

    【讨论】:

      猜你喜欢
      • 2011-03-04
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多