0

I'm halfway through a CMS where the URL is an SEO friendly name based on a page title. There is a need for one section to use a specific controller. So for example:

test.com/page1 (uses index controller) test.com/page2 (uses index controller) test.com/page3 (uses different controller) test.com/page4 (uses index controller)

I could add a route that says "page3" will use the "different" controller, but the users of the CMS need to be able to change the name and seo of the URL, so where it is currently "page3" it could be changed later which would break my Routing rule.

What's the best way (either front controller plug in or other) to grab the request and pull the controller to be used from the DB (sql would be like "SELECT controller FROM menu WHERE seo = 'page3'"), then set that as the controller before Zend sets the controller to be used?

Any help or insight is greatly appreciated.

1 Answer 1

1

You will have to create a controller plugin and set the module/controller/action on the request object.

Then in the predispatch() you can do something like this:

public function preDispatch(Zend_Controller_Request_Abstract $request)
{
    $request->setModuleName($this->_getModule());
    $request->setControllerName($this->_getController());
    $request->setActionName($this->_getAction());
}

And then you can create methods __getModule(), _getController(), _getAction() that will examine the $_SERVER['REQUEST_URI'] and your DB and set the appropriate module/controller/action.

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

3 Comments

Thanks for the reply. Should the functions you mention all be part of the frontController plugin? Let's say I make the plugin called updateControllerSeo, the functions preDispatch and _getController would be part of that class plugin? Thanks again.
Yes. They should be in plugin. But I would suggest putting them in routeShutdown(), as in this case they would be called before every action (if you use action view hleper, or so...)
Create all this methods in the plugin. If they are not in your plugin class you can not call them using ($this). And the preDispatch() or the routeShutdown() are needed because they are the "hooks" that are invoked during the dispatch cycle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.