0

By default you have the following URL-syntax in ZF: /module/controller/action. What i want, is to build an menu-system where i can use any URL I want.

Lets say I make an menu-item called 'news'. When i call http://www.site.com/news i want to have the folowing loaded:

  • module: news
  • controller: frontpage
  • action: display

These config-values must be configured in the database-record for the menu-item.

How can I do this in zend? I spend a lot of time searching for it, but I still can't figure out how to. Does anybody?

2 Answers 2

1

I'd suggest using a front controller plugin to scan your database for all the entries, create routing rules based on those entries and add them to the router (see this).

Of course caching strategy is recommended so that you don't do a lot of processing on every request.

Sign up to request clarification or add additional context in comments.

2 Comments

Can't I just load only the used item?
Yes, you can. But if you want to generate nice links to other pages (using the url view helper), you will need all (well, potentially all) the routes defined anyway.
0

You can create a plugin and in routeStartup define something that intercept your request and route /module/controller/action to /action, but for this all your action names must be unique :

 class My_CustomRouterPlugin extends Zend_Controller_Plugin_Abstract { public function routeStartup(Zend_Controller_Request_Abstract $request) { $fc = Zend_Controller_Front::getInstance(); $action =$fc->getRequest()->getActionName(); $router = $fc->getRouter(); $model= new myModel(); $myPage = $model->getPageByAction($action); $route = new Zend_Controller_Router_Route('/action', array( 'module' => $myPage->getModule(); 'controller' => $myPage->getController(); 'action' => $action; )); $router->addRoute($action, $route); return $router; } } 

In myModel define a method can get you an object(or an array) that contains module, controller names (from you DB ).

and register this plugin in your bootstrap:

$front->registerPlugin(new My_CustomRouterPlugin()); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.