Skip to content

Instantly share code, notes, and snippets.

@macnibblet
Created June 27, 2012 11:34
Show Gist options
  • Save macnibblet/3003508 to your computer and use it in GitHub Desktop.
Save macnibblet/3003508 to your computer and use it in GitHub Desktop.
<?php
/**
* @author Antoine Hedgecock <antoine@pmg.se>
*/
/**
* @namespace
*/
namespace MCNCore\View\Helper;
use MCNCore\Object\AbstractObject,
Zend\View\Helper\AbstractHelper,
Zend\ServiceManager\ServiceLocatorInterface,
Zend\ServiceManager\ServiceLocatorAwareInterface;
/**
*
*/
class SlugUrl extends AbstractHelper implements ServiceLocatorAwareInterface
{
/**
* @var ServiceLocatorInterface
*/
protected $sm;
/**
* @param ServiceLocatorInterface $serviceLocator
*
* @return SlugUrl
*/
public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->sm = $serviceLocator;
return $this;
}
/**
* @return ServiceLocatorInterface
*/
public function getServiceLocator()
{
return $this->sm;
}
/**
* @param $name
* @param AbstractObject $object
* @return mixed
*/
public function __invoke($name, AbstractObject $object)
{
$parameters = array(
'id' => $object->getId(),
'slug' => $object->getUrlSlug()
);
/*
foreach($this->router->getRoute($name)->getParams() as $param => $value)
{
// if the param exists in the object then use that instead of default value..
if ($object->offsetExists($param)) {
$parameters[$param] = $object->offsetGet($param);
} else {
$parameters[$param] = $value;
}
}
*/
return $this->getView()
->url($name, $parameters);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment