1

In my project i created a Helper to display a-tags, but with an additonal check, if the user has ACL rights. When he has access to the url, i want to create the Url with the existing UrlHelper - but i can't instantiate it:

// try 1
$pluginHelper = \Zend\Mvc\Service\ViewHelperManagerFactory::createService($this->getServiceLocator());
$this->_urlHelper = $pluginHelper->get('url');

// try 2
$factory = new \Zend\Mvc\Service\RouterFactory();
$router = $this->_urlHelper = $factory->createService($this->getServiceLocator());

// try 3
$module = new \RDGOnline\Module();
$config = $module->getConfig();
$router = \Zend\Mvc\Router\Http\TreeRouteStack::factory($config['router']);

$this->_urlHelper = new Url();
$this->_urlHelper->setRouter($router);

I attempted different ways, but all failed. In my last try the url was created - but it ignores the subfolder. I.E. /trunk/

Thanks for Helping.

1 Answer 1

2

If you're doing this inside a view helper, you can access view helpers (plugins) through the injected view's plugin method

public function someViewHelperMethod()
{
    $urlHelper = $this->view->plugin('url');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.