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:
  1. // url - http://localhost/Test/www/:controller/:action
  2. $router = new Zend_Controller_RewriteRouter();
  3. $router->setRewriteBase('/Test/www/');
  4. $controller->setRouter($router);

Seems to be working so far.

del.icio.us:Quick snip  digg:Quick snip  furl:Quick snip  reddit:Quick snip

5 Responses to Quick snip

  1. Marco :

    /* — 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.

  2. PHPDeveloper.org :

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

  3. Pádraic Brady :

    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 …

  4. Nick Lo :

    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/’);

  5. lig :

    Thanks for the heads up guys.

Leave a Reply