Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / AbstractFormAutocomplete.php
Last active August 29, 2015 14:03
Abstract Autocomplete Form View Helper ZF2 issue #4221
<?php
namespace Application\Form\View\Helper;
use Zend\Form\View\Helper\FormText;
use Zend\Form\ElementInterface as ElementInterface;
class AbstractFormAutocomplete extends FormText
{
protected $foo;
@webdevilopers
webdevilopers / DoctrineDebugDump.php
Last active August 29, 2015 14:03
Doctrine Debug dump usage instead of var_dump
<?php
/**
* Lazy load proxies always contain an instance of Doctrine’s EntityManager and all its dependencies.
* Therefore a var_dump() will possibly dump a very large recursive structure which is impossible to render and read.
* You have to use Doctrine\Common\Util\Debug::dump() to restrict the dumping to a human readable level.
* Additionally you should be aware that dumping the EntityManager to a Browser may take several minutes,
* and the Debug::dump() method just ignores any occurrences of it in Proxy instances.
*/
#var_dump($entity); // will possibly dump a very large recursive structure which is impossible to render and read
@webdevilopers
webdevilopers / CreateContactForm.php
Last active August 29, 2015 14:03
ZF2 How to add fieldset to form and remove element from it
<?php
namespace Application\Form;
use Zend\Form\Form;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class CreateContractForm extends Form
implements ServiceLocatorAwareInterface
{
@webdevilopers
webdevilopers / simple_response.php
Last active June 8, 2017 17:44
ZF2 How to return XML response
<?php
$rawXml = '<foo><bar>Baz</bar></foo>';
$response = new \Zend\Http\Response();
// Instead of header("Content-type: text/xml; charset=utf-8") use:
$response->getHeaders()->addHeaderLine('Content-Type', 'text/xml; charset=utf-8');
$response->setContent($rawXml);
return $response;
@webdevilopers
webdevilopers / CanEditContractAssertion.php
Created July 15, 2014 12:27
ZfcRbac assertion example using factories
<?php
namespace Application\Assertions;
use ZfcRbac\Assertion\AssertionInterface;
use ZfcRbac\Service\AuthorizationService;
class CanEditContractAssertion implements AssertionInterface
{
/**
@webdevilopers
webdevilopers / sf2_controller.php
Last active August 29, 2015 14:04
Client cURL multipart form-data POST to JasperReportsEngine Servlet
<?php
namespace Plusquam\Bundle\ContractBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
class BundleController extends Controller
{
public function egzAction()
{
@webdevilopers
webdevilopers / ContractState.php
Last active August 29, 2015 14:04
Symfony2 (static) Translation with Doctrine Extensions using Gedmo or / and Stof and messages.locale.domain
<?php
namespace Acme\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
/**
* @ORM\Entity
@webdevilopers
webdevilopers / dump.sql
Last active August 29, 2015 14:05
MySQL - Join row to get latest change in one single row
--
-- Database: `webdevilopers`
--
-- --------------------------------------------------------
--
-- Table structure for table `contracts`
--
@webdevilopers
webdevilopers / alternative_performant_having_query.sql
Last active August 29, 2015 14:05
MySQL perfomance impact on COUNT DISTINCT when adding subquery to WHERE condition with 20000 rows in parent table
SELECT COUNT(DISTINCT a.angebot_id),
ash.angebot_status_datum,
(
SELECT MAX(ash2.angebot_status_datum)
FROM angebot_status_historie ash2
WHERE ash2.angebot_id = a.angebot_id
) AS current_state
FROM
angebot a
JOIN angebot_status_historie ash USING (angebot_id)
@webdevilopers
webdevilopers / Offer.php
Last active January 13, 2016 15:17
Sonata Admin datagrid filter returning last created row using MAX() on DATETIME on a one-to-many relation
<?php
/**
* Offer
*
* @ORM\Table(name="angebot", indexes={
* ...
* })
* @ORM\Entity
*/