2009-12-18 67 views
2

有沒有什麼辦法從服務類中獲取Action Helper?Zend Controller Action,請幫助其他課程?

我有以下助手:

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工作不喜歡例外(;

class My_Service_XYZ { 

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

} 

回答

7
class My_Service_XYZ { 

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

    } 

應該工作

0

也許你應該嘗試:

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

而不是:

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

該死的複製和粘貼;)是主機不閃.. – opHASnoNAME 2009-12-18 19:28:47

相關問題