views:

167

answers:

1
+2  Q: 

ZF routing problem

Hello,

I just started my adventure with zend framework 1.9.1 but I encountered few issues. I would like to remove default routes to avoid displaying the same content on different URLs - to achive it I wrote custom function in bootstraper

<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initMyRouter()
    {
        $this->bootstrap('router')
             ->getContainer()
             ->frontcontroller
             ->getRouter()
             ->removeDefaultRoutes();
    }
}

but after that, one problem arise - every invalid URL reaches to default controller instead of error controller. To solve this issue I put resources.frontController.defaultcontrollername = "error" resources.frontController.defaultaction = "throw" in application.ini and

public function throwAction()
{
    throw new Zend_Controller_Dispatcher_Exception;
}

in ErrorController to workaround this but my question is... am I doing something wrong?

The second issue is that I need to generate only absolute URLs so I added resources.frontController.baseurl = "http://mydomain.com/" in application.ini but after that every URL points to default controller. How to fix it?

The third (and last) is... how to call Zend_Controller_Action_Helper_Url::url in my actions? I tried something like $this->_helper->url(array(), 'frontpage') but it calls Zend_Controller_Action_Helper_Url::direct

+1  A: 

I'll answer number three first as I can tell you off the top of my head.

I generally use $this->view->url(array(...), 'routeName', true); the last argument resets the parameters. I find that the view helper is a little easier/quicker to type than the Action Helper. Although I think $this->_helper->url->url(...) is the proper way to get to the action helper.

I've never removed the default route - but if there aren't any other answers later in the day - I'll do my best to do some testing for you after work hours.

gnarf