Open hattingen opened 9 years ago
inject from service manager is necessary here. as rough example.
class Link extends AbstractTable
{
/**
* @var ServiceLocatorInterface
*/
protected $viewHelperManager;
protected $config = array(
'name' => 'Link decorator',
'showPagination' => true,
'showQuickSearch' => false,
'showItemPerPage' => true,
);
/**
* @var array Definition of headers
*/
protected $headers = array(
'id' => array('title' => 'Id', 'width' => '50') ,
//...
);
/**
* @param ServiceLocatorInterface $viewHelperManager
*/
public function setViewHelperManager(ServiceLocatorInterface $viewHelperManager)
{
$this->viewHelperManager = $viewHelperManager;
}
/**
* @return ServiceLocatorInterface
*/
public function getViewHelperManager()
{
return $this->viewHelperManager;
}
/**
* @param $name
* @param $args
*
* @return mixed
*/
public function __call($name, $args)
{
return call_user_func_array($this->getViewHelperManager()->get($name), $args);
}
public function init()
{
$this->getHeader('id')->getCell()->addDecorator('callable', array(
'callable' => function($context, $record){
return '<a href="' . $this->url('your route name', [$record->getUuid()]) ' . '">'.$record->getId().'</a>';
}
));
}
}
$tblGrid = new Link(/*...*/);
$vhm = $di->get('viewHelperManager');
$tblGrid->setViewHelperManager($vhm);
Thx. Have it working now. My tries were similar, but I missed the last part.
I am using the callable decorator like this:
Is it possible to use the view helper and routes here?