red888
red888

Reputation: 31642

ZF2: Trying to understand Zend\Form

I'm new to Zend and honestly frameworks\larger scale OOP projects in general. I think figuring out how this little piece works would go a long why to improving my understanding. When using setAttribute to register the form with a controller, what is actually reading the ur() property I set?

Here is a snippet:

$form = $this->form;
$form->prepare();
$form->setAttribute('action', $this->url(NULL,
    array('controller'=>'Register','action'=> 'process')));
$form->setAttribute('method','post');
echo $this->form()->openTag($form);

What is actually reading 'controller'=>'Register' and associating it with my Register controller?

Upvotes: 2

Views: 83

Answers (1)

Tim Fountain
Tim Fountain

Reputation: 33148

This part of your code:

$this->url(NULL, array('controller'=>'Register','action'=> 'process'))

is calling the URL helper. This call will output a path, based on your routing configuration, along the lines of /register/process. You are setting the 'action' attribute of the form to this value, giving you HTML something along the lines of:

<form method="post" action="/register/process">

so that's what makes the form submit to your register controller.

Upvotes: 5

Related Questions