Which is better: A new controller to send POST arg

2019-07-27 19:13发布

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.

2条回答
劫难
2楼-- · 2019-07-27 20:00

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.

查看更多
【Aperson】
3楼-- · 2019-07-27 20:04

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

查看更多
登录 后发表回答