Zend Controller Action,在其他类中获取Helper?

时间:2009-12-18 06:41:34

标签: php zend-framework

有没有办法从服务类中获取Action 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;
    }
}

现在我想从“My_Service_XYZ”获取主机名,getStaticHelper不能像excepted一样工作(;

class My_Service_XYZ {

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

}

2 个答案:

答案 0 :(得分:8)

    class My_Service_XYZ {

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

    }

应该有效

答案 1 :(得分:0)

也许你应该尝试:

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

而不是:

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