d3bug3r
d3bug3r

Reputation: 2586

Zend Application Controller Helper Accessing View Helper

Hi i have a controller helper as follow:

<?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;

    }

}

and i have a view helper as follow for 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));
    }
}

?>

I cant access Application view helper in Application controller helper, where i might be wrong!!

Upvotes: 0

Views: 1016

Answers (1)

drew010
drew010

Reputation: 69927

The abstract class Zend_Controller_Action_Helper_Abstract doesn't provide a $view property which reflects the view object that the controller is using.

If you want to get access to the view object from your action helper, use the following code:

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

Once you have that you should be able to call your view helper like:

$view->getEventTime(...);

Upvotes: 4

Related Questions