Skip to content

Instantly share code, notes, and snippets.

@manuakasam
Last active August 29, 2015 14:01
Show Gist options
  • Save manuakasam/ea1ac02fa812c3d3e291 to your computer and use it in GitHub Desktop.
Save manuakasam/ea1ac02fa812c3d3e291 to your computer and use it in GitHub Desktop.
<?php
foreach ($this->myhelper as $rowObject) {
echo $rowObject->getName();
}
<?php
class HelperFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $sl)
{
$realSL = $sl->getServiceLocator();
$repository = $realSL->get('Doctrine\ORM\EntityManager')->getRepository('My\Repository');
return new MyHelper($repository);
}
}
<?php
return [
'view_helpers' => [
'factories' => [
'myhelper' => 'My\Namespace\HelperFactory'
]
]
];
<?php
class MyHelper extends AbstractHelper
{
protected $repo;
public function __construct(ObjectRepository $repo)
{
$this->repo = $repo;
}
public function __invoke($id)
{
return $this->repo->findBy([
'id' => $id
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment