Reputation: 75
I am a starter in zend-framework 2.
If i need to create a link in view.phtml
, using this:
$this->url('router',array())
Now i need to create a link in controller and save to database. Any Idea?
Upvotes: 6
Views: 8170
Reputation: 2058
invoke viewhelper:
public function algoAction()
{
$url = $this->getServiceLocator()
->get('viewhelpermanager')
->get('url');
$link = $url('router',array());
}
zf v2.4
also
$this->url()->fromRoute('home',[],['force_canonical' => true]);
['force_canonical' => true] *is optional
Upvotes: 3
Reputation: 1623
try this:
public function someAction()
{
//codes
//use url plugin in controller
$link = $this->url()->fromRoute('router', array());
//or use ViewHelperManager in controller or other place that you have ServiceManager
$link = $this->getServiceLocator()->get('ViewHelperManager')->get('url')->__invoke('router',array());
//codes
}
Upvotes: 15
Reputation: 383
Use url() controller plugin:
public function fooAction(){
//other code
$this->url('routename');
//other stuff
}
Upvotes: -1