Zend Controller Action , get Helper in other class?

心已入冬 提交于 2019-12-24 01:48:11

问题


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..
    }

}

回答1:


    class My_Service_XYZ {

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

    }

should works




回答2:


Maybe you should try:

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

instead of:

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


来源:https://stackoverflow.com/questions/1926710/zend-controller-action-get-helper-in-other-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!