Which is better: A new controller to send POST arguments or use the current one? Zend Framework 2

こ雲淡風輕ζ 提交于 2019-12-11 10:50:05

问题


What type of API is this?

This is a followup question regarding an API question I had.

I am using Zend Framework 2.

zf-skeleton/module/MyApplication/src/MyApplication/Controller/IndexController.php

public function submitAction() {
     $myForm = new MyForm();
     $myForm->get('submit')->setValue('Add');         

     $request = $this->getRequest();
     if ($request->isPost()) {
     $myModel = new MyModel();
     $myForm->setInputFilter($myModel->getInputFilter());
     $myForm->setData($request->getPost());

     if ($myForm->isValid()) {
         // Form is validated. [1]

Now the form is validated, do I send the POST arguments to another action within this controller or create a new controller?

I am looking for best practices.


回答1:


As for best practices, In a small scale application , it would be unwise to create a new controller. But when we talk about a large scale application, each piece is done seperately, and new controller is recommended. So, it totally depends on your application.




回答2:


never use controller inside a controller. if you want to share a common method in multiple controllers you must create a component(for cakephp framework) or a controller plugin (for zend). visit http://lab.empirio.no/custom-controller-plugin-in-zf2.html



来源:https://stackoverflow.com/questions/35579209/which-is-better-a-new-controller-to-send-post-arguments-or-use-the-current-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!