Zend应用程序控制器助手访问View Helper

时间:2012-10-01 10:49:43

标签: php zend-framework

您好我有一个控制器助手如下:

<?php

class Application_Controller_Helper_GetEventDetail extends Zend_Controller_Action_Helper_Abstract
{

    public function direct($eventDetail)
    {
        return $this->getEventDetail($eventDetail);
    }

    public function getEventDetail($event_id)
    {
        $eventMapper = new Application_Model_Mapper_EventMapper();      
        $eventDetails = $eventMapper->findById($event_id);
        $eventDate = $this->view->getEventTime($eventDetails[0]['date_from'],$eventDetails[0]['date_to']);

        $result = array(
            'event' => $eventDetails,
            'when' => $eventDate
            );

        return $result;

    }

}

我有getEventTime

的视图助手
<?php

class Application_View_Helper_GetEventTime extends Zend_View_Helper_Abstract
{

    public function getEventTime($fromdate,$todate)
    {
        //echo $to; exit;
         return date("j F Y, H:m a",strtotime($fromdate))."-<br/>".date("j F Y, H:m a",strtotime($todate));
    }
}

?>

我无法在Application controller helper中访问Application view helper,我可能错了!!

1 个答案:

答案 0 :(得分:4)

抽象类Zend_Controller_Action_Helper_Abstract没有提供反映控制器正在使用的视图对象的$view属性。

如果要从操作助手访问视图对象,请使用以下代码:

$view = $this->getActionController()->view;

一旦你拥有了这个,你应该可以调用你的视图助手,如:

$view->getEventTime(...);