How do I use the Zend Framework Service Locator in a Model? I have a class that I would like to use the a Table Gateway Model in. I have followed the Album example and would like to access the table outside of the controller. However if I copy and paste the code from the controller into the class I need it I get an error (undefined method :getServiceLocator()). How do I use this 'class' outside of the controller?
In the end I would like to access the functions in the " class AlbumTable" in something other then the controller (in this case another class). Thanks.
class Calendar implements ServiceLocatorAwareInterface{
protected $serviceLocator;
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
}
public function getServiceLocator()
{
return $this->serviceLocator;
}
/*
* Create Calendar Sync Table
*/
public function getCalendarSyncTable()
{
if (!$this->calendarSyncTable) {
$sm = $this->getServiceLocator();
$this->calendarSyncTable = $sm->get('Pro\Model\CalendarSync\CalendarSyncTable');
}
return $this->calendarSyncTable;
}
Needed to change how I called it in the controller to
$calendar = $this->getServiceLocator()>get('Pro\Model\GoogleCalendar\Calendar');