Quick snip

Am playing a bit with the ZF – basically doing shiflett’s tutorial on it, when I came upon a bit of a problem.

*Right about here I should note I haven’t even looked at the ZF in almost a year and quite a bit has changed.

Anyway – I am using a subfolder of web root to play with the ZF and was having troubles getting my controller to go to the correct place. After considering hacking both the Apache doc root and the actual Zend_Controller_Router code and writing a patch, I stumbled on the answer – Zend_Controller_RewriteRouter.

[php]
// url – http://localhost/Test/www/:controller/:action
$router = new Zend_Controller_RewriteRouter();
$router->setRewriteBase(‘/Test/www/’);
$controller->setRouter($router);
[/php]

Seems to be working so far.

Comments (21)

MarcoDecember 6th, 2006 at 8:09 am

/* — create a router — */

$router = new Zend_Controller_RewriteRouter();
$router->addRoute(‘user’, ‘user/:username’, array(‘controller’ => ‘user’, ‘action’ => ‘info’));

/* — set it in a controller — */

$ctrl = Zend_Controller_Front::getInstance();
$ctrl->setRouter($router);

this should work. but dont forget that the rewriteBase will be autodetected with the rewrite router.

PHPDeveloper.orgDecember 6th, 2006 at 1:35 pm

Ligaya Turmelle’s Blog: Quick snip (or Zend Framework in a Subdirectory)…

Pádraic BradyDecember 6th, 2006 at 8:30 pm

Bear in mind there will be a few changes when the next release introduces the new MVC architecture that was only included in 0.20 in the incubator classes. ;) It’s not all that far away …

Nick LoDecember 7th, 2006 at 8:08 am

As Pádraic mentioned there are changes afoot one of which is to use…

$controller->setBaseUrl(‘/Test/www/’);
$controller->setRouter($router);

…instead of…

$router->setRewriteBase(‘/Test/www/’);

ligDecember 7th, 2006 at 9:11 am

Thanks for the heads up guys.