Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / AbstractFormAutocomplete.php
Last active Aug 29, 2015
Abstract Autocomplete Form View Helper ZF2 issue #4221
View AbstractFormAutocomplete.php
<?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 Aug 29, 2015
Doctrine Debug dump usage instead of var_dump
View DoctrineDebugDump.php
<?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 Aug 29, 2015
ZF2 How to add fieldset to form and remove element from it
View CreateContactForm.php
<?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 Jun 8, 2017
ZF2 How to return XML response
View simple_response.php
<?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 Jul 15, 2014
ZfcRbac assertion example using factories
View CanEditContractAssertion.php
<?php
namespace Application\Assertions;
use ZfcRbac\Assertion\AssertionInterface;
use ZfcRbac\Service\AuthorizationService;
class CanEditContractAssertion implements AssertionInterface
{
/**
@webdevilopers
webdevilopers / sf2_controller.php
Last active Aug 29, 2015
Client cURL multipart form-data POST to JasperReportsEngine Servlet
View sf2_controller.php
<?php
namespace Plusquam\Bundle\ContractBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
class BundleController extends Controller
{
public function egzAction()
{
@webdevilopers
webdevilopers / ContractState.php
Last active Aug 29, 2015
Symfony2 (static) Translation with Doctrine Extensions using Gedmo or / and Stof and messages.locale.domain
View ContractState.php
<?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 Aug 29, 2015
MySQL - Join row to get latest change in one single row
View dump.sql
--
-- Database: `webdevilopers`
--
-- --------------------------------------------------------
--
-- Table structure for table `contracts`
--
@webdevilopers
webdevilopers / alternative_performant_having_query.sql
Last active Aug 29, 2015
MySQL perfomance impact on COUNT DISTINCT when adding subquery to WHERE condition with 20000 rows in parent table
View alternative_performant_having_query.sql
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 Jan 13, 2016
Sonata Admin datagrid filter returning last created row using MAX() on DATETIME on a one-to-many relation
View Offer.php
<?php
/**
* Offer
*
* @ORM\Table(name="angebot", indexes={
* ...
* })
* @ORM\Entity
*/