views:

35

answers:

2

hi,

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

I want 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,

+2  A: 

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

DASPRiD
issue here that it uses it doesnt check if a controller exsits. And it is kind of a default. For example if i have www.domain.com/user/ and "user" is a controller it tries to make username
Sharon Barky
Well you surely can only use this if you are using custom routes only, and not the default module route, which twitter is doing so as well by the way.
DASPRiD
yes that's what i thought, cheers
Sharon Barky
A: 

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");

Sharon Barky