Zend Framework: subdirectories in the controller directory

I use the Zend Framework for my site and just created a special "api" module to create ... Well, the API.

Now I have many controllers in my module, and I would like to create subdirectories in this controller directory in order to "remove" it. My new structure would be something like this:

 - controllers/
 - controllers/contents/[controllers]
 - controllers/users/[controllers]
 - controllers/misc/[controllers]

However, I cannot completely find which URLs and redirects with Zend_Controller_Router_Route can be displayed on these controllers. Is it possible to do this anyway, should I just go back to the normal structure and put all my controllers in the same directory?


I tried using _ separators, as suggested by smack0007, and as it seemed logical, given how the Zend Framework usually refers to subdirectories, but I got an error.


Edit: deleted the long text of the error because it was not related to the question, because it was only a problem, because I did not use the propre argument, believing that I had to put a capital letter in the first letter of the directory. Now everything is working well.

+3
source share
2 answers

I did this in the project back in version 1.5, but I don’t know if it will work anymore.

You must attach your controllers to "{FOLDER} _", and then use the fully qualified name in the URL.

, :

contents_FooController

:

/contents_foo/index
+3

URL- URL-. URL-.

modules
 --test
   --controllers
     --sub
        -- OtherController.php
     --DefaultController.php

Bootstrap.php :

public function __construct($application)
    {
        parent::__construct($application);
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->addControllerDirectory(__DIR__ . '/controllers',
            'test');
        $frontController->addControllerDirectory(__DIR__ . '/controllers/sub',
            'test_sub');
    }

DefaultController.php

class Test_DefaultController extends Zend_Controller_Action {
     public function subAction()
    {
         $level1 = $this->getRequest()->getParam('level1');
         $level2 = $this->getRequest()->getParam('level2');
         return $this->_forward($level2, $level1, 'test_sub');
    }

, .

, :

new Zend_Controller_Router_Route_Regex('([a-z-]+)/([a-z-]+)/([a-z-]+)/([a-z-]+)/([a-z-]+)',
    array(),
    array(1 => 'module', 2 => 'controller', 3 => 'action', 4 => 'level1', 5 => 'level2'),
    '%s/%s/%s/%s/%s'
)

test/default/sub/other/index indexAction OtherController.php

0

Source: https://habr.com/ru/post/1735924/


All Articles