2010年3月1日星期一

RE: [fw-mvc] Generated urls to map to controllers and actions

Hi,

Thanks for the reply.

The biggest problem with this solution, is the fact that I won't be able to use the url view helper (assembling my url).

Should I create a new route class extending Zend_Controller_Router_Route_Abstract, and add that one to the router of the frontcontroller?

$this->bootstrap('frontController');
$fc = $this->frontController;
$router = $fc->getRouter();
$route = new My_Route(...);
$router->addRoute('cms', $route);

This way, my default route should still be working, and the 'normal' router is used.

Is this the correct way?

Regards,
Jachim Coudenys

-----Oorspronkelijk bericht-----
Van: Viktor Grandgeorg [mailto:info@intelligibel.de]
Verzonden: vrijdag 26 februari 2010 20:55
Aan: fw-mvc@lists.zend.com
Onderwerp: RE: [fw-mvc] Generated urls to map to controllers and actions

Hi,

I think a good start could be to write a Controller Plugin, something like:

<?php
class Controllers_Plugin_Maproutes extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
Zend_Registry::set('zfRequestController', $request->getControllerName());
Zend_Registry::set('zfRequestAction', $request->getActionName());

$oYourMappingTable = new MappingTable();

if($oYourMappingTable->isMappable($request->getControllerName(), $request->getActionName())) {
$request->setControllerName($oYourMappingTable->getMappedControllerName());
$request->setActionName($oYourMappingTable->setMappedActionName());
} else {
// route to error (or pass the request to a next route...)
$request->setControllerName('error');
$request->setActionName('error');
}
}
}

Regards, Viktor

> -----Original Message-----
> From: Jachim Coudenys [mailto:Jachim.Coudenys@guideline.be]
> Sent: Friday, February 26, 2010 8:55 AM
> To: fw-mvc@lists.zend.com
> Subject: [fw-mvc] Generated urls to map to controllers and actions
>
> Hi,
>
> I'm searching for a correct solution for a routing problem
> I'm struggling with for quite a while now, but I can't
> extract the answer out of the Zend_Controller_Router manual page.
>
> Our system produces friendly url's lik this:
> - language/catagory/category/product
> - language/catagory
> - language/category/product/article
> - language/section/page/subpage
> - etc...
>
> This can be quite long/deep (the customer organizes its
> tree), but I can map a controller/action/id/etc... to every url.
>
> I've tried to subclass the router, but that overrides the
> complete routing section.
>
> I want to be able to check for a record in my mapping table
> (url to controller/etc...), but pass the request to a next
> route (with translated segments and the 'normal' route e.g.)
> when no mapping could be done.
>
> The nicest thing would be if I could use assemble() to create
> a url base don the mapping table.
>
> Do I need a router, or a route and how would I get started?
>
> Thanks in advance!
>
> Regards,
> Jachim Coudenys
>


This email was Anti Virus scanned.

没有评论: