Last active
August 29, 2015 14:01
-
-
Save manuakasam/ea1ac02fa812c3d3e291 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
foreach ($this->myhelper as $rowObject) { | |
echo $rowObject->getName(); | |
} |
This file contains hidden or 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 | |
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); | |
} | |
} |
This file contains hidden or 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 | |
return [ | |
'view_helpers' => [ | |
'factories' => [ | |
'myhelper' => 'My\Namespace\HelperFactory' | |
] | |
] | |
]; |
This file contains hidden or 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 | |
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