2010年2月26日星期五

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
>

没有评论: