有没有办法从服务类中获取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..
}
}
答案 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');