[fw-general] Re: Using custom router. Where exactly?
vadim gavrilov wrote: Where exactly do you place the router? In the bootstrap file? in the index? How can you make a custom router for each module you have? Examples will be highly appreciated. You can take a look at Matthews Pastebin application. He uses a modular directory structure and each module has its own bootstrap class. In these classes you have access to the Initialize plugin and the frontcontroller instance. http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/library/My/Plugin/Initialize.php http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/application/modules/spindle/Bootstrap.php Now you can use the getRouter() method of the frontcontroller and then add new custom routes with addRoute(). Hope this helps.
Re: [fw-general] Re: Using custom router. Where exactly?
Thanks i already looked at those files. Still can i place an instance of the addRoute inside a certain controller? or do i need to place it somewhere in the bootstarp file? Basically what i would like to do is to make a file that will hold all the routes for each module/controller. Did anyone made something like that before? Thanks. On Mon, Mar 2, 2009 at 2:22 PM, Jens Kleikamp j...@codes-concepts.comwrote: vadim gavrilov wrote: Where exactly do you place the router? In the bootstrap file? in the index? How can you make a custom router for each module you have? Examples will be highly appreciated. You can take a look at Matthews Pastebin application. He uses a modular directory structure and each module has its own bootstrap class. In these classes you have access to the Initialize plugin and the frontcontroller instance. http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/library/My/Plugin/Initialize.php http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/application/modules/spindle/Bootstrap.php Now you can use the getRouter() method of the frontcontroller and then add new custom routes with addRoute(). Hope this helps. -- Vincent Gabriel. Lead Developer, Senior Support. Zend Certified Engineer.
Re: [fw-general] Re: Using custom router. Where exactly?
On Mon, Mar 2, 2009 at 13:33, vadim gavrilov vadim...@gmail.com wrote: Thanks i already looked at those files. Still can i place an instance of the addRoute inside a certain controller? or do i need to place it somewhere in the bootstarp file? Basically what i would like to do is to make a file that will hold all the routes for each module/controller. Did anyone made something like that before? The best file is for me routes.ini. in config directory;-) The rest in bootstrap initRoutes. Regards, pch -- Paweł Chuchmała pawel.chuchmala at gmail dot com
Re: [fw-general] Re: Using custom router. Where exactly?
Any example for this? Since i saw that Matthew didn't use any router. 2009/3/2 Paweł Chuchmała pawel.chuchm...@gmail.com On Mon, Mar 2, 2009 at 13:33, vadim gavrilov vadim...@gmail.com wrote: Thanks i already looked at those files. Still can i place an instance of the addRoute inside a certain controller? or do i need to place it somewhere in the bootstarp file? Basically what i would like to do is to make a file that will hold all the routes for each module/controller. Did anyone made something like that before? The best file is for me routes.ini. in config directory;-) The rest in bootstrap initRoutes. Regards, pch -- Paweł Chuchmała pawel.chuchmala at gmail dot com -- Vincent Gabriel. Lead Developer, Senior Support. Zend Certified Engineer.
[fw-general] Re: [fw-mvc] Re: [fw-general] Re: Using custom router. Where exactly?
Routes should be defined in a bootstrap or in a routeStartup() of a front controller plugin. When the dispatch loop reaches the controller, the router has already been invoked so any rules you add inside controllers are useless (they can still be used to generate URLs in the controller and view, but without the corresponding routing rule the URLs generated would probably lead to nowhere unless the said rule is a subset of an existing rule or the default one). Module-specific rules are impossible for the same reason. The closest thing to such a thing is to have rules defined in module bootstraps which are loaded in every request. They are not really module-specific rules though, but merely routing rules that are organized per module. I do exactly that in http://code.google.com/p/mz-project/ . -- Mon On Mon, Mar 2, 2009 at 8:33 PM, vadim gavrilov vadim...@gmail.com wrote: Thanks i already looked at those files. Still can i place an instance of the addRoute inside a certain controller? or do i need to place it somewhere in the bootstarp file? Basically what i would like to do is to make a file that will hold all the routes for each module/controller. Did anyone made something like that before? Thanks. On Mon, Mar 2, 2009 at 2:22 PM, Jens Kleikamp j...@codes-concepts.comwrote: vadim gavrilov wrote: Where exactly do you place the router? In the bootstrap file? in the index? How can you make a custom router for each module you have? Examples will be highly appreciated. You can take a look at Matthews Pastebin application. He uses a modular directory structure and each module has its own bootstrap class. In these classes you have access to the Initialize plugin and the frontcontroller instance. http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/library/My/Plugin/Initialize.php http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/application/modules/spindle/Bootstrap.php Now you can use the getRouter() method of the frontcontroller and then add new custom routes with addRoute(). Hope this helps. -- Vincent Gabriel. Lead Developer, Senior Support. Zend Certified Engineer.
Re: [fw-general] Re: [fw-mvc] Re: [fw-general] Re: Using custom router. Where exactly?
Thanks, I will sure looking at the way your doing it. On Mon, Mar 2, 2009 at 3:53 PM, Mon Zafra mon...@gmail.com wrote: Routes should be defined in a bootstrap or in a routeStartup() of a front controller plugin. When the dispatch loop reaches the controller, the router has already been invoked so any rules you add inside controllers are useless (they can still be used to generate URLs in the controller and view, but without the corresponding routing rule the URLs generated would probably lead to nowhere unless the said rule is a subset of an existing rule or the default one). Module-specific rules are impossible for the same reason. The closest thing to such a thing is to have rules defined in module bootstraps which are loaded in every request. They are not really module-specific rules though, but merely routing rules that are organized per module. I do exactly that in http://code.google.com/p/mz-project/ . -- Mon On Mon, Mar 2, 2009 at 8:33 PM, vadim gavrilov vadim...@gmail.com wrote: Thanks i already looked at those files. Still can i place an instance of the addRoute inside a certain controller? or do i need to place it somewhere in the bootstarp file? Basically what i would like to do is to make a file that will hold all the routes for each module/controller. Did anyone made something like that before? Thanks. On Mon, Mar 2, 2009 at 2:22 PM, Jens Kleikamp j...@codes-concepts.comwrote: vadim gavrilov wrote: Where exactly do you place the router? In the bootstrap file? in the index? How can you make a custom router for each module you have? Examples will be highly appreciated. You can take a look at Matthews Pastebin application. He uses a modular directory structure and each module has its own bootstrap class. In these classes you have access to the Initialize plugin and the frontcontroller instance. http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/library/My/Plugin/Initialize.php http://github.com/weierophinney/pastebin/blob/b796ad0e5905e46b312a5b904a2a80c3ed8ff808/application/modules/spindle/Bootstrap.php Now you can use the getRouter() method of the frontcontroller and then add new custom routes with addRoute(). Hope this helps. -- Vincent Gabriel. Lead Developer, Senior Support. Zend Certified Engineer. -- Vincent Gabriel. Lead Developer, Senior Support. Zend Certified Engineer.
Re: [fw-general] Re: Using custom router. Where exactly?
-- vadim gavrilov vadim...@gmail.com wrote (on Monday, 02 March 2009, 03:15 PM +0200): Any example for this? Since i saw that Matthew didn't use any router. The router is used on every request -- I simply wasn't defining any custom *routes* -- and herein lies your confusion, I think. Zend_Controller_Router_Regex is registered with the front controller by default. This router, by default, registers a route that corresponds to (:module/):controller/:action/*. I you want any additional routes, you must register them yourself -- and you must do so *before* the router is invoked. Router invocation is the first part of the front controller's dispatch() routine. You have two places you can then register routes: your bootstrap, or in a routeStartup() plugin. The current stable pastebin app uses an Initialize plugin that is registered with routeStartup(), and could be easily modified to do route initialization if necessary. On the whole, however, it's rare that you will need to do explicit, custom routes per controller; if you are, you may want to re-think your routing strategy to make it more predictable and uniform. As for custom routes per module, you have several options. * In your bootstrap, loop through each module directory and check for a route bootstrap (a similar tack is taken in the upcoming Zend_Application), configuration file, and/or plugin. * Use a config file to define routes for your entire application. * Use a routeStartup() plugin that checks each module directory for a configuration file defining routes for that module. 2009/3/2 Pawe Chuchma a pawel.chuchm...@gmail.com On Mon, Mar 2, 2009 at 13:33, vadim gavrilov vadim...@gmail.com wrote: Thanks i already looked at those files. Still can i place an instance of the addRoute inside a certain controller? or do i need to place it somewhere in the bootstarp file? Basically what i would like to do is to make a file that will hold all the routes for each module/controller. Did anyone made something like that before? The best file is for me routes.ini. in config directory;-) The rest in bootstrap initRoutes. Regards, pch -- Pawe Chuchma a pawel.chuchmala at gmail dot com -- Vincent Gabriel. Lead Developer, Senior Support. Zend Certified Engineer. -- Matthew Weier O'Phinney Software Architect | matt...@zend.com Zend Framework | http://framework.zend.com/
Re: [fw-general] Re: Using custom router. Where exactly?
In one of my apps: routes.ini: routes.main.type = Zend_Controller_Router_Route_Regex routes.main.route = (main.php|index.html) routes.main.defaults.controller = index routes.main.defaults.action = index (...) Initialize.php class XXX_Plugin_Initialize extends Zend_Controller_Plugin_Abstract { (...) public function routeStartup(Zend_Controller_Request_Abstract $request) { $this-initRoutes(); (...) } public function initRoutes() { $router = $this-_front-getRouter(); $routing_config = new Zend_Config_Ini($this-_appPath . '/config/routes.ini', 'production'); $router-addConfig($routing_config, 'routes'); } } index.php or bootstrap.php or something like this (...) $front-registerPlugin(new XXX_Plugin_Initialize((...))) -addControllerDirectory(APPLICATION_PATH . '/controllers'); (...) regards, pch 2009/3/2 vadim gavrilov vadim...@gmail.com: Any example for this? Since i saw that Matthew didn't use any router. 2009/3/2 Paweł Chuchmała pawel.chuchm...@gmail.com On Mon, Mar 2, 2009 at 13:33, vadim gavrilov vadim...@gmail.com wrote: Thanks i already looked at those files. Still can i place an instance of the addRoute inside a certain controller? or do i need to place it somewhere in the bootstarp file? Basically what i would like to do is to make a file that will hold all the routes for each module/controller. Did anyone made something like that before? The best file is for me routes.ini. in config directory;-) The rest in bootstrap initRoutes. Regards, pch -- Paweł Chuchmała pawel.chuchmala at gmail dot com -- Vincent Gabriel. Lead Developer, Senior Support. Zend Certified Engineer. -- Paweł Chuchmała pawel.chuchmala at gmail dot com