Error in ZF3 Tutorial Using zend-hydrator with zend-form


#1

Hi

Everything in the blog tutorial works fine except for the edit action. Accessing the /blog/edit/id it renders the form well but the fields (text and title) display not data to edit.

Debugging Blog/view/blog/write/form.phtml first 5 lines of code:

$form = $this->form;
xdebug_debug_zval('form');
$fieldset = $form->get('post');
xdebug_debug_zval('fieldset');

The form debug output shows the data to edit:

(refcount=7, is_ref=0)
object(Blog\Form\PostForm)[167]
  protected 'attributes' => (refcount=1, is_ref=0)
    array (size=3)
      'method' => (refcount=1, is_ref=0)string 'POST' (length=4)
      'name' => (refcount=1, is_ref=0)string 'postform' (length=8)
      'action' => (refcount=1, is_ref=0)string '/is/blog/edit/1' (length=15)
...
protected 'object' => (refcount=2, is_ref=0)
        object(Blog\Model\Post)[246]
          private 'id' => (refcount=2, is_ref=0)string '1' (length=1)
          private 'text' => (refcount=2, is_ref=0)string 'Welcome to my first blog post' (length=29)
          private 'title' => (refcount=2, is_ref=0)string 'Blog #1' (length=7)

but the debug output of the fieldset does not:

(refcount=3, is_ref=0)
object(Blog\Form\PostFieldset)[173]
  protected 'factory' => (refcount=3, is_ref=0)
    object(Zend\Form\Factory)[169]
      protected 'inputFilterFactory' => (refcount=0, is_ref=0)null
      protected 'formElementManager' => (refcount=4, is_ref=0)
        object(Zend\Form\FormElementManager\FormElementManagerV3Polyfill)[60]
          protected 'aliases' => (refcount=1, is_ref=0)
            array (size=72)
              ...
protected 'object' => (refcount=1, is_ref=0)
    object(Blog\Model\Post)[193]
      private 'id' => (refcount=0, is_ref=0)null
      private 'text' => (refcount=1, is_ref=0)string '' (length=0)
      private 'title' => (refcount=1, is_ref=0)string '' (length=0)
  protected 'useAsBaseFieldset' => (refcount=0, is_ref=0)boolean   false

I rechecked the code with the one in the tutorial and is identical.
What could have I missed?


#2

Hi Thorito and welcome to the forum! :smiley:

Can you check the init method of your form class, because this line:

protected 'useAsBaseFieldset' => (refcount=0, is_ref=0)boolean   false

indicates that something is missing.

// In /module/Blog/src/Form/PostForm.php:

public function init()
{
    $this->add([
        'name' => 'post',
        'type' => PostFieldset::class,
        'options' => [
            'use_as_base_fieldset' => true, // Do you have this line?
        ],
    ]);

https://docs.zendframework.com/tutorials/in-depth-guide/zend-form-zend-form-fieldset/#using-zend-hydrator-with-zend-form


#3

Thanks froschdesign

yes i do have that line.

This are the complete debug dump:
debug

the code


#4

That’s just the modules. If you include the application dir on down, I’ll run it and have a look…


#5

Thanks Greg_Bell

Here is the link to code.

Better late than never.