Override the default route, but call it if necessary

I am developing a website with the following URLs:

site.com/james
site.com/james/photos

The scheme for these URLs is: site.com/USERNAME/APPLICATION

The username and application name are checked using the db yb program logic. I set a route for this, but Zend directs all requests to this route.

But there are the same controllers and admin module. When I go to site.com/admin, it looks for the username "admin". Or when I go to site.com/james/profile, it tries to find an application called "profile". But there is an action in the ActionController for this.

How can I implement this feature? For example, a front controller that looks for controller names and sends them a request if the controller exists?

+3
source share
3 answers

Look at the redefinition of the Zend_Controller_Action method __call($method, $args), which is called if the desired action cannot be found. You can put site.com/USERNAME/APPLICATION check logic in the __call method of, say, the default controller (or where it makes sense) and return to using the default route.

+2
source

In general, if you do this, you will have to restore the default routes again for them to work. This literally means adding a route that matches / admin and goes to the admin module.

, . , URL- - site.com/user/james site.com/user/james/photos.

, -, , , , / :

$front->setParam('useDefaultControllerAlways', true);

IndexController:: indexAction

+2

I would use a route chain . Delete the default routes and add them to the end of the chain.

In the end, the front controller plug-in for handling conditions.

0
source

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


All Articles