views:

32

answers:

2

i need advice on how i can implement this action helper. currently, i have something like

class Application_Controller_Action_Helper_AppendParamsToUrl extends Zend_Controller_Action_Helper_Abstract {
    function appendParamsToUrl($params = array()) {
        $router = Zend_Controller_Front::getInstance()->getRouter();
        $url = $router->assemble($params);

        if (!empty($_SERVER['QUERY_STRING'])) {
            $url .= $_SERVER['QUERY_STRING'];
        }
        return $url;
    }
}

but as you can see, i think the function should be a static function? but how will that find into this Zend_Controller_Action_Helper thingy?

+2  A: 

Make the function public and in your BootStrap.php ensure the controller helper can be autoloaded

// add paths to controller helpers
Zend_Controller_Action_HelperBroker::addPath( APPLICATION_PATH .'/controllers/helpers');

You should then be able to call the helper from your controller via

$this->_helper->appendParamsToUrl->appendParamsToUrl();
emeraldjava
+1  A: 

You can also rename appendParamsToUrl() function to direct()

function direct( $params = array() ) {...}

In this case, you'll be able to access it from controller with

$this->_helper->appendParamsToUrl( $params );
Vika