Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / Cast.php
Last active August 29, 2015 14:06
DoctrineExtensions\Query\Mysql\Cast.php
<?php
namespace Plusquam\Bundle\ContractBundle\DoctrineExtensions\Query\Mysql;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Literal;
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\SqlWalker;
@webdevilopers
webdevilopers / ContractAdmin.php
Created September 24, 2014 12:31
Translating dynamic vars concatening object property in twig template using SonataAdminBundle
<?php
namespace Acme\DemoBundle\Admin;
use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
class ContractAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
@webdevilopers
webdevilopers / Contract.php
Last active August 29, 2015 14:07
Batch resp. mass editing symfony form type using Doctrine Entity using data transformation and events
<?php
namespace Plusquam\Bundle\ContractBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
class Contract
{
/**
* @ORM\OneToMany(targetEntity="TimekeepingEntry", mappedBy="contract", cascade={"persist"})
@webdevilopers
webdevilopers / TimekeepingController.php
Last active August 29, 2015 14:08
Uniform date picker and form element in symfony depending on locale resp. default_locale
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
@webdevilopers
webdevilopers / Version20141112104658.php
Last active August 29, 2015 14:09
Schema commands not executed in postUp() method while prepared statements in queries are executed even with --write-sql option in Doctrine Migrations
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@webdevilopers
webdevilopers / acme_layout.html.twig
Last active August 29, 2015 14:09
Override FOSUserBundle resp. SonataUserBundle resp. ApplicationSonataUserBundle layout.html.twig template
{% extends "TwigBundle::layout.html.twig" %}
{% block head %}
<link rel="icon" sizes="16x16" href="{{ asset('favicon.ico') }}" />
{% block stylesheets %}
<link rel="stylesheet" href="/bundles/sonatacore/vendor/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="{{ asset('/bundles/sonatacore/vendor/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css') }}" />
@webdevilopers
webdevilopers / DormerRequestType.php
Last active August 29, 2015 14:10
Assert entity is selected if checkbox is checked with Expression Constraint - Symfony2 Form Validation
<?php
namespace AppBundle\Form;
use Symfony\Component\Form\FormBuilderInterface;
class DormerRequestType extends BaseRequestType
{
public function buildForm(FormBuilderInterface $builder, array $options) {
switch ($options['flow_step']) {
@webdevilopers
webdevilopers / PriceQuoteRequest.php
Last active August 29, 2015 14:13
How to use Symfony2 Validation Constraint Callback with validation groups to validate a single property
<?php
namespace Acme\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* PriceQuoteRequest
@webdevilopers
webdevilopers / .htaccess
Created January 22, 2015 08:49
How to use Symfony2 Full Stack and Components with legacy PHP flat app
# Use the front controller as index file. It serves as a fallback solution when
# every other rewrite/redirect fails (e.g. in an aliased environment without
# mod_rewrite). Additionally, this reduces the matching process for the
# start page (path "/") because otherwise Apache will apply the rewriting rules
# to each configured DirectoryIndex file (e.g. index.php, index.html, index.pl).
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
@webdevilopers
webdevilopers / security.yml
Created January 27, 2015 12:28
How to redirect after successful login setting default_target_path on all firewalls using FOSUserBundle and SonataAdminBundle in Symfony2 Security
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
# set access_strategy to unanimous, else you may have unexpected behaviors
access_decision_manager:
strategy: unanimous
providers: