du248227 2013-04-19 02:13
浏览 29
已采纳

可捕获致命错误:类Zend \ Form \ View \ Helper \ FormLabel [关闭]的对象

Catchable fatal error: Object of class Zend\Form\View\Helper\FormLabel could not be converted to string in (...)\module\Application\view\application\produtos\form.phtml on line 2

form.phtml

<?php echo $this->form()->openTag($form);?>
<?php echo $this->formLabel($form->get('nome_produto'));?>
<?php echo $this->formElement($form->get('nome_produto'));?>
<?php echo $this->formErrors($form->get('nome_produto'));?>
<?php echo $this->form()->closeTag($form);?>

ProdutosController.php

public function novoAction()
{
    $form = new ProdutoForm();

    $view = new ViewModel(array(
            'form' => $form
    ));
    $view->setTemplate('application/produtos/form.phtml');
    return $view;
}

ProdutoForm.php

    <?php

namespace Application\Form;

use Zend\Form\Form;
use Zend\Form\Element\Text;

class ProdutoForm extends Form
{
public function __construct($name = null) {
    parent::__construct('produto');

    $nome = new Text('nome_produto');
    $nome->setLabel('Nome: ')
         ->setAttributes(array(
            'class' => 'input-mediun'
         ));
    $this->add($nome);

...

  • 写回答

1条回答 默认 最新

  • douchixu3686 2013-04-19 02:23
    关注

    Yeah those form view helpers should really have better error detection. I'm guessing $form->get('nome_produto') is returning null. As a result the FormLabel view helper is simply returning itself since it has nothing to actually render. The echo command is then trying to cast the view helper to a string.

    Double check the element name and make sure you're getting the right item from the form.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。