I collided in a problem and I can not find a good solution to do this work. I have to make some dynamic routes in the Zend Framework Project. I soon understand what my problem is:
I need dynamic custom routes that increase the default route (" then Actually, I have worked to use this same routes below. I also need the routes to work without the partner set, which is the default method ( From your description, it seems that you are looking for one where your Partners is an optional series. There is a similar question here, but using the hostname route:. I have optimized it to resolve my problem, just put the following in my Bootstrap.php to start routing: Change as you see fit. In your controllers, you can get only one value for the partner parameter if it was indeed specified and valid (if a partner is not present then you will get a routing error) ... module / controller / action / parameter "] The project I am working for has many partners and the routes have to work with them. I have made a static class to store the partners and it looks like this. < Pre>
& lt ;? php class App_P Artner {static public $ partners = array (array ('name' = & gt; 'array' ('name' = & gt; 'partner2', 'picture' = & gt; 'partner2.jpg'), array ('name 'Partner1', 'picture' = & gt; 'partner1.jpg' partner3 ',' picture '=>' partner3.jpg ')); Fixed public function pathpad () {$ partners = Array (); foreign currency (auto :: Partners as partner $) {array_push ($ partners, strollger ($ partner ['name']))}} $ Regex = '(' .implode ('|', $ Partners). '); Return $ regex;}}
App_Partner :: routePartners () me
(partner1 | Partner2 | Partner3) Return a string that I use to create the right path My goal is for custom paths for each participant, which I have done for each route defined in the bootstrap. So if I have a route, then
add-product.html set I want to do it for each participant because
Partner2 / add- Product.html and
partner3 / add-product.html Additionally,
partner1 / ,
partner2 / , < Code> partner3 to the route
default / index / index .
& lt ;? Php $ routeProposal = new Zend_Controller_Router_Route_Regex ('App_Partner :: MargPorters)' '? /?' 1 ',' page '= & gt; 1) array (' module '= & gt;' default ',' controller '= & gt; ; 'Proposal', 'verb' = & gt; 'index', 'partner'), "% s / proposals.html"); $ Router- & gt; Add-root ('proposal', $ root portrait); The above path works fine if I use a partner in the request URI, but if I do not, So to get the
"% s / proposals.html" , get double slash like
public // proposals.html due to the reverse route set in the path given above There is no way to avoid this reverse route because I can create my own URL using the
add-product.html ,
proposals.html etc. ) Will happen.
protected function _initRoute () {$ this- & Gt; Bootstrap ('FrontController'); $ Router = $ this- & gt; GetResource ('Front-Controller') - & gt; GetRouter (); // Default route $ router- & gt; Deleted Default Roots (); $ DefaultRoute = New Zend_Controller_Router_Route (': Controller /: Action / *', array ('module' = & gt; 'default', 'controller' = & gt; 'index', 'action' => index ' ,)); $ Router- & gt; Add-ons ('default', $ defaultRoute); $ PartnerRoute = New Zend_Controller_Router_Route (': partner', array ('partner' = & gt; 'none'), array ('partner' = & gt; '^ (partner1 | partner2 | partner3) $') ); $ Router- & gt; Add-root ('partner', $ partner routing- & gt; series ($ defaultRoute)); }
Comments
Post a Comment