Zend Controller Action , get Helper in other class

2019-07-20 18:07发布

is there any way to get an Action Helper from an Service Class?

I have the following Helper:

class Helper_Host extends Zend_Controller_Action_Helper_Abstract
{
    /**
     * Return Hosturl with path
     *
     * @return string Hostname
     */
    public function direct()
    {
        $front = Zend_Controller_Front::getInstance();
        $host = 'http://' . $_SERVER['HTTP_HOST'];
        $host .= $front->getBaseUrl() . '/';
        return (string) $host;
    }
}

Now i want to get the Hostname from "My_Service_XYZ" , getStaticHelper is not working like excepted (;

class My_Service_XYZ {

    public function test()
    {
        $h = Zend_Controller_Action_HelperBroker::getStaticHelper('Host');
        return $h->host(); // not working..
    }

}

2条回答
我只想做你的唯一
2楼-- · 2019-07-20 18:39

Maybe you should try:

$h = Zend_Controller_Action_HelperBroker::getStaticHelper('Host');

instead of:

$h = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
查看更多
可以哭但决不认输i
3楼-- · 2019-07-20 18:53
    class My_Service_XYZ {

        public function test()
        {
            $h = Zend_Controller_Action_HelperBroker::getStaticHelper('Host');
            return $h->direct(); // not working..
        }

    }

should works

查看更多
登录 后发表回答