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);
...
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.