ZF2:试图理解Zend\Form

red*_*888 2 forms zend-framework2

我是Zend的新手,老实说框架\大规模的OOP项目.我认为弄清楚这件小作品是如何运作的,这将有助于提高我的理解力.当使用setAttribute向控制器注册表单时,实际读取ur()我设置的属性是什么?

这是一个片段:

$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);
Run Code Online (Sandbox Code Playgroud)

什么是实际读取'controller'=>'Register'并将其与我的Register控制器相关联?

Tim*_*ain 5

这部分代码:

$this->url(NULL, array('controller'=>'Register','action'=> 'process'))
Run Code Online (Sandbox Code Playgroud)

正在调用URL帮助器.此调用将根据您的路由配置输出路径/register/process.您正在将表单的"action"属性设置为此值,为您提供以下行的HTML:

<form method="post" action="/register/process">
Run Code Online (Sandbox Code Playgroud)

这就是表格提交给你的注册管理员的原因.