【问题标题】:Write hyperlink inside the Zend Form and use routes?在 Zend Form 中编写超链接并使用路由?
【发布时间】:2012-02-21 09:40:14
【问题描述】:

我有一个登录表单,想在里面添加一个“丢失密码”链接。我发现你可以使用描述来做到这一点。但我现在已经开始更改所有内容以使用路由,并希望将其用于忘记密码链接。有没有机会这样做?我找不到解决方案,你们中的任何人都知道该怎么做吗?

 $password = new Zend_Form_Element_Password('login_password', array(
    'label'         => 'Password',
    'description'   => '<a href="account/lost">Forgot Password ?</a>',
            'required'  => true,    
            ));
$password->getDecorator('description')->setOptions(array('escape' => false, 'placement' => 'APPEND')); 

【问题讨论】:

    标签: zend-framework


    【解决方案1】:

    我之前也遇到过同样的问题,得到了答案

    Write hyperlink inside the Zend Form?

    也可以帮到你……

    【讨论】:

      【解决方案2】:

      创建 Zend_Form 时,您无权访问 View_Helpers,因为表单不需要视图实例。因此,您要么必须在表单的 init 方法中获取视图,要么稍后添加描述(我更喜欢后者)。

      当第一种方法时,你必须获取 Zend_Controller_Front-instance 然后它的视图,最后调用视图助手,例如Zend_View_Helper_Url 来自那个视图。

      后者可以通过稍后添加描述来实现,例如当您将表单传递给视图时(或在将表单传递给视图之前在控制器中):

      <?php
          $description = '<a href="' . $this->url([...]); . '"'>forgot password?</a>
          $this->form->getElement('login_password')->setDescription($description);
          echo $this->form;
      ?>
      

      【讨论】:

      • 很棒的答案麻雀!我使用了控制器解决方案,因此我获取了密码元素并使用了 setDescription,之后我使用 getDecorator('Description')->setOptions 来包含 'escape' => false,否则超链接将被写入文本。优秀的。如果你知道怎么做就很容易了:)非常感谢!!
      猜你喜欢
      • 2011-08-18
      • 2011-03-18
      • 1970-01-01
      • 2010-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-28
      相关资源
      最近更新 更多