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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?