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?
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
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With