I'm trying to access the service locator in a view helper so i can access to my config. I'm using this view helper for a recursive function so i don't know where to declare the service locator.
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
use CatMgt\Model\CategoryTable as RecursiveTable;
class CategoryRecursiveViewHelper extends AbstractHelper
{
protected $table;
public function __construct(RecursiveTable $rec)
{
$this->table = $rec;
}
public function __invoke($project_id, $id, $user_themes_forbidden, $level, $d, $role_level)
{
$config = $serviceLocator->getServiceLocator()->get('config');
//So i can access $config['templates']
$this->__invoke($val->project_id, $id, $user_themes_forbidden, $level, $d, $role_level);
}
}
I tried the solution give here link
But it didn't helped, is it all right to do it that way?
namespace Application\View\Helper;
use Zend\View\Helper\AbstractHelper;
use CatMgt\Model\CategoryTable as RecursiveTable;
use Zend\View\HelperPluginManager as ServiceManager;
class CategoryRecursiveViewHelper extends AbstractHelper
{
protected $table;
protected $serviceManager;
public function __construct(RecursiveTable $rec, ServiceManager $serviceManager)
{
$this->table = $rec;
$this->serviceManager = $serviceManager;
}
public function __invoke($project_id, $id, $user_themes_forbidden, $level, $d, $role_level)
{
$config = $this->serviceManager->getServiceLocator()->get('config');
//So i can access $config['templates']
$this->__invoke($val->project_id, $id, $user_themes_forbidden, $level, $d, $role_level);
}
}