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 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi