Create a subdirectory in the Forms folder of ZF2

1

I am building a system in ZF2, in a controller I have many different forms, but in the same module I have many controller with many forms, and to make everything more ordered I want to create a subdirectory in the folder Forms called Specials and leave all my special forms there, leaving my directory structure in the following way

module/
Account/
    config/
    Controller/
    Form/
        Specials/
    Model/
    view/

In the controller I add line use Account\Forms\Specials\SpecialForm1 , then I call it $special_form1 = new SpecialForm1("form_special1); but that gives me the error not found

Someone knows how I can do this please.

    
asked by albertcito 09.08.2016 в 23:27
source

1 answer

1

With a structure like the one proposed, Zend constructs the namespace of each module from the directory that is inside src (at least in the traditional skeleton).

module
├── Account
│   ├── config
│   │   └── module.config.php
│   ├── src
│   │   └── Account
│   │       ├── Controller
│   │       │   └── IndexController.php
│   │       ├── Model
│   │       │   └── MyModel.php
│   │       └── Form
│   │           └── Specials
│   │               └── SpecialForm1.php
│   ├── view
│   │   ├── account
│   │   │   └── index
│   │   │       └── index.phtml
│   │   └── layout
│   │       └── layout.phtml
│   └── Module.php
│...

If we simplify the scheme to the class that we want to instantiate, in this case the class SpecialForm1 , it would be like this.

.
└── Account
    └── Form
        └── Specials
            └── SpecialForm1.php

The namespace of the class SpecialForm1 would be like this:

namespace Account\Form\Specials;

And to instantiate it from the controller we can use it in the following way:

use Account\Form\Specials\SpecialForm1;

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        // utilizando el namespace del operador use
        $form = new SpecialForm1();
    }
}
    
answered by 10.08.2016 / 13:08
source