Created
September 16, 2012 09:45
-
-
Save AndrejAndb/3731809 to your computer and use it in GitHub Desktop.
Sample custom Url Helper for CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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