Skip to content

Instantly share code, notes, and snippets.

View davidwindell's full-sized avatar

David Windell davidwindell

View GitHub Profile
<?php
namespace Application\Mvc\Router\Http;
use Zend\Mvc\Router\Http\Hostname as HttpHostname;
use Zend\Stdlib\RequestInterface as Request;
use Zend\Mvc\Router\Http\RouteMatch;
use Zend\ServiceManager\ServiceManagerAwareInterface;
use Zend\ServiceManager\ServiceManager;
// Setup Navigation
$container = new Navigation(include __DIR__ . '/config/navigation.config.php');
$renderer->plugin('navigation')->setContainer($container);
\Zend\Navigation\Page\Mvc::setDefaultRouter($e->getRouter());
$app->getEventManager()->attach(MvcEvent::EVENT_DISPATCH, array($this, 'persistEntities'));
public function persistEntities(MvcEvent $e) {
try {
$em = $e->getApplication()->getServiceManager()->get('doctrine.entitymanager.orm_default');
$em->flush();
} catch (\PDOException $exception) {
$e->setError('persist-error')
->setParam('exception', $exception);
$e->getApplication()->getEventManager()->trigger('dispatch.error', $e);
use DoctrineORMModule\Form\Annotation\AnnotationBuilder;
$entity = new \Application\Entity\Account;
$builder = new AnnotationBuilder($this->getServiceLocator()->get('doctrine.entitymanager.orm_default'));
$infoForm = $builder->createForm($entity);
Results:
Fatal error: Call to undefined method Doctrine\ORM\Mapping\Column::getLength() in /home/david/domains/public_html/vendor/doctrine/doctrine-orm-module/src/DoctrineORMModule/Form/Annotation/ElementAnnotationsListener.php on line 225
<?php
<?php
public function getServiceConfiguration() {
return array(
'factories' => array(
'my_identity_provider' => function($sm) {
$identity = $sm->get('Zend\Authentication\AuthenticationService')->getIdentity();
return $identity ? $identity : Entity\Contact::ROLE_GUEST;
},
),
);
<?php
/**
* Process input data and return as array based on content type
* support types json/xml/urlencoded form data
*
* @param Request $request
* @return array
*/
public function processInput(Request $request)
<?php
public function setPosts(array $posts) {
foreach ($posts as $post) {
if ($this->posts->contains($post)) {
return;
}
$this->posts->add($post);
$post->setTicket($this);
@davidwindell
davidwindell / gist:3181965
Created July 26, 2012 13:12
ZF2 Select Element bound to Object
<?php
namespace My\Form\Element;
use Zend\Form\Element\Select as SelectElement;
class DepartmentSelect extends SelectElement
{
<?php
'doctrine' => array(
'configuration' => array(
'orm_default' => array(
//'sqlLogger' => new \Doctrine\DBAL\Logging\EchoSQLLogger(),
),
),
),
{
"ticket": {
"ticketid": 174,
"status": "open",
"type": "ticket",
"subject": "Hello there",
"followup": false,
"contact": {
"contactid": 99,
"name": "Person",