Skip to content

Instantly share code, notes, and snippets.

View fabiopaiva's full-sized avatar

Fábio Paiva fabiopaiva

  • Skyworkz
  • Amsterdam
View GitHub Profile
@fabiopaiva
fabiopaiva / RenderForm.php
Last active April 15, 2016 09:29
ZF2 Custom Form Render
<?php
namespace Application\View\Helper;
//use Zend\View\Helper\AbstractHelper;
use Zend\Form\View\Helper\AbstractHelper;
use Zend\Form\Form;
class RenderForm extends AbstractHelper {
@fabiopaiva
fabiopaiva / DateHydrator.php
Created August 25, 2014 17:33
Date in d/m/Y format ZF2 + Doctrine + Form
<?php
namespace Application\Hydrator;
use DoctrineModule\Stdlib\Hydrator\DoctrineObject;
class DateHydrator extends DoctrineObject {
protected function handleTypeConversions($value, $typeOfField) {
if ($typeOfField == 'date') {
@fabiopaiva
fabiopaiva / ExampleController.php
Created September 19, 2014 12:58
ZF2 global configuration
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class ExampleController extends AbstractActionController{
public function indexAction() {
$config = $this->getServiceLocator()->get('Config');
$example = $config['example'];
@fabiopaiva
fabiopaiva / MyController.php
Last active August 29, 2015 14:06
ZF2 + Doctrine + Form example
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Application\Form\MyForm;
class MyController extends AbstractActionController {
@fabiopaiva
fabiopaiva / Module.php
Last active August 29, 2015 14:07
Assign serviceLocator to a custom view helper in Zend Framework 2
<?php
namespace Application;
class Module{
public function getViewHelperConfig() {
return array(
'factories' => array(
'myHelper' => function($sm){
@fabiopaiva
fabiopaiva / Module.php
Created November 25, 2014 11:40
BjyAuthorize + Navigation
<?php
namespace Application;
use Zend\Mvc\MvcEvent;
class Module{
public function onBootstrap(MvcEvent $e) {
$sm = $e->getApplication()->getServiceManager();
// Add ACL information to the Navigation view helper
$authorize = $sm->get('BjyAuthorizeServiceAuthorize');
@fabiopaiva
fabiopaiva / bjyAuthorize.config.php
Created December 5, 2014 22:02
My Bjyauthorize configuration
<?php
return array(
'bjyauthorize' => array(
'default_role' => 'Visitante',
// Using the authentication identity provider, which basically reads the roles from the auth service's identity
'identity_provider' => 'BjyAuthorize\Provider\Identity\AuthenticationIdentityProvider',
'role_providers' => array(
// using an object repository (entity repository) to load all roles into our ACL
'BjyAuthorize\Provider\Role\ObjectRepositoryProvider' => array(
@fabiopaiva
fabiopaiva / DateDiff.php
Last active August 29, 2015 14:11
ZF2 + Doctrine Custom Function Mysql DateDiff
<?php
namespace Application\DoctrineFunction;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
class DateDiff extends FunctionNode {
/*
* holds the timestamp of the DATE_FORMAT DQL statement
@fabiopaiva
fabiopaiva / PersonController.php
Last active August 29, 2015 14:11
Find person using LIKE command in multiple fields with Doctrine2 and ZF2
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class PersonController extends AbstractActionController{
public function searchAction(){
$term = $this->params()->fromQuery('term', '');
$qb = $this
->getServiceLocator()
@fabiopaiva
fabiopaiva / index.js
Created July 6, 2015 20:46
Angular + Apigility pagination
angular.module('app')
.controller('IndexCtrl', function ($scope){
$scope.navigate('http://host-api/index');
});