开发者

zend Default controller action, before going to error

couldn't find my solution. hope you can help.

I wa开发者_开发百科nt to have a url (like twitter) www.domain.com/USERNAME

what happen it goes to the error controller. i want it to go to a different controller in these cases. Some kind of default controller if none found.

Appreciated a small example or any info.

Thanks,


You should create a custom route for that:

:username

But make sure, that you add this route first, so that following routes can match. For information about custom rotues, see the documentation of the router:

http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes


Got it to work with the following.

Placed this code in the bootstrap.

$front = $this->getResource("frontController");
$front = Zend_Controller_Front::getInstance();
 $router = $front->getRouter();

 $route = new Zend_Controller_Router_Route('/:username', array('controller' => 'index','action' => 'user'));

 $router->addRoute('minipage', $route);

An alternative for this is placing the rules in the config.ini:

routes.router.type = "Zend_Controller_Router_Route"
routes.router.route = "/:username"
routes.router.defaults.controller = "index"
routes.router.defaults.action = "minipage"

;rules for the exception to the above rulles.

routes.indexItem.type =Zend_Controller_Router_Route
routes.indexItem.route               = cms
routes.indexItem.defaults.controller    = cms
routes.indexItem.defaults.action        = index


routes.indexItem2.type =Zend_Controller_Router_Route
routes.indexItem2.route               = policy
routes.indexItem2.defaults.controller    = policy
routes.indexItem2.defaults.action        = index


routes.indexItem3.type =Zend_Controller_Router_Route
routes.indexItem3.route               = index
routes.indexItem3.defaults.controller    = index
routes.indexItem3.defaults.action        = index

And load this from the bootstrap using

$front->getRouter()-> addConfig(new Zend_Config_Ini(APPLICATION_PATH . "/configs/routes.ini"), "routes");

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜