Skip to content

Instantly share code, notes, and snippets.

@AndrejAndb
Created September 16, 2012 09:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrejAndb/3731809 to your computer and use it in GitHub Desktop.
Save AndrejAndb/3731809 to your computer and use it in GitHub Desktop.
Sample custom Url Helper for CLI
<?php
namespace Application;
class Module implements \Zend\ModuleManager\Feature\ViewHelperProviderInterface
{
public function getViewHelperConfig() {
return array(
'factories' => array(
'HttpUrl' => function ($sm) {
$helper = new \Zend\View\Helper\Url;
$locator = $sm->getServiceLocator();
$httpRouter = $locator->get('http_router');
// site domain may be retrieved from config
$httpRouter->setRequestUri(new \Zend\Uri\Http('http://sample.com/'));
$helper->setRouter($httpRouter);
return $helper;
},
),
);
}
}
namespace Application\Controller;
class IndexController extends \Zend\Mvc\Controller\AbstractActionController {
public function testurlAction(){
$vm = new \Zend\View\Model\ViewModel();
$vm->setTemplate('application/index/testurl');
$renderer = $this->getServiceLocator()->get('ViewManager')->getRenderer();
$text = $renderer->render($vm);
echo $text;
}
}
?>
template application/index/testurl.phtml:
<?php echo $this->http_url('home/blog_entry', array('id' => 'entry1'), array('force_canonical' => true)); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment