php - Shorten Zend Framework Route Definitions -


How can I define the definition of my custom routes in the Z Framework? I currently have this definition as:

  $ route = new Zend_Controller_Router_Route (": module /: id", array ("controller" =>> "index", "action" = & Gt; "index"), array ("id" = & gt; "\ d +")); Auto: $ frontController- & gt; GetRouter () - & gt; Add-ons ('shortcut-on', $ route); $ Route = new Zend_Controller_Router_Route (": module /: controller /: id", array ("Action" => gt; "index"), array ("id" => "\ d +")); Auto: $ frontController- & gt; GetRouter () - & gt; Add-ons ('shortcutto', $ route); $ Route = new Zend_Controller_Router_Route (": module /: controller /: action /: id", blank, array ("id" => gt; "\ d +")); Auto: $ frontController- & gt; GetRouter () - & gt; Add-ons ('shortcut', $ route);  

Is there any way to better combine these rules? And what is your best practice in these places? I currently have them right after the front controller initialization in their bootstrap class.

When it comes to set up path in this way, I use a config file As a preference, I use XML to store my configuration data, although it can be easily stored in any other supported format. After this I add the router to the router from the config in my bootstrap.

Config:

  & lt; Config & gt; & Lt; Routes & gt; & Lt; ShortcutOn = "Zend_Controller_Router_Route" & gt; & Lt; Route & gt ;: module /: id & lt; / Route & gt; & Lt; Missed & gt; & Lt; Controller & gt; Index & lt; / Controller & gt; & Lt; Action & gt; Index & lt; / Action & gt; & Lt; / Missed & gt; & Lt; Reqs id = "\ d +" & gt; & Lt; / Shortcutone & gt; & Lt; Shortcut to type = "Zend_Controller_Router_Route" & gt; & Lt; Route & gt ;: module /: controller /: id & lt; / Route & gt; & Lt; Missed & gt; & Lt; Controller & gt; Index & lt; / Controller & gt; & Lt; / Missed & gt; & Lt; Reqs id = "\ d +" & gt; & Lt; / Shortcuttwo & gt; & Lt; ShortcutsThree = "Zend_Controller_Router_Route" & gt; & Lt; Route & gt ;: module /: controller /: action /: id & lt; / Route & gt; & Lt; Missed & gt; & Lt; Controller & gt; Index & lt; / Controller & gt; & Lt; Action & gt; Index & lt; / Action & gt; & Lt; / Missed & gt; & Lt; Reqs id = "\ d +" & gt; & Lt; / Shortcutthree & gt; & Lt; / Routes & gt; & Lt; / Config & gt;  

Bootstrap

  $ config = new Zend_Config_Xml ('config.xml'); $ Router = Zend_Controller_Front :: getInstance () - & gt; GetRouter (); $ Router- & gt; Andenfig ($ config, 'route');  

Obviously, there are other options and I encourage you to read it, however, it fits for your example.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -