Skip to content

Instantly share code, notes, and snippets.

View smottt's full-sized avatar

Metod smottt

View GitHub Profile
<?php
$connectionParams = array(
"dbname" => "CHANGEME",
"user" => "CHANGEME",
"password" => "CHANGEME",
"host" => "localhost",
"driver" => "pdo_mysql"
);
<?php
public function someAction()
{
$response = $this->get("response");
$response->setContent("This is some text.");
return $response;
}
<?php
public function someAction()
{
$this->getResponse()->setContent("This is some text.");
return sfView::NONE;
}
@smottt
smottt / services.yml
Last active September 26, 2015 09:28
Symfony2 Custom Login Even Listener
services:
login_listener:
class: 'Acme\UserBundle\Listener\LoginListener'
arguments: ['@security.context', '@doctrine']
tags:
- { name: 'kernel.event_listener', event: 'security.interactive_login' }
@smottt
smottt / LoginListener.php
Last active December 17, 2015 06:56
Symfony2 Custom Login Even Listener
<?php
namespace Acme\UserBundle\Listener;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Core\SecurityContext;
use Doctrine\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.1.0+
// use Symfony\Bundle\DoctrineBundle\Registry as Doctrine; // for Symfony 2.0.x
/**
@smottt
smottt / gist:1306215
Created October 22, 2011 17:00
Symfony2 return sfView::NONE
<?php
namespace Acme\AcmeBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
class SomeController
{
public function testAction()
{
@smottt
smottt / gist:1397845
Created November 27, 2011 17:19
PagerfantaBundle Symfony2 Controller Example
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller,
Symfony\Component\HttpFoundation\Request,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Method,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Route,
Sensio\Bundle\FrameworkExtraBundle\Configuration\Template,
Pagerfanta\Pagerfanta,
Pagerfanta\Adapter\DoctrineORMAdapter,
Pagerfanta\Exception\NotValidCurrentPageException;
@smottt
smottt / config.yml
Created January 15, 2012 14:11
CHAR_LENGTH doctrine2 DQL function in symfony2
# app/config/config.yml
doctrine:
orm:
entity_managers:
default:
dql:
numeric_functions:
char_length: Acme\DemoBundle\Extension\Doctrine\Query\Mysql\CharLength
@smottt
smottt / template.html.twig
Created January 16, 2012 15:12
Check if symfony2 form has errors in a twig template
{% if form.get('errors') is not empty %}
Magic errors display!
{% endif %}
<?php
/**
* DoctrineExtensions Mysql Function Pack
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* If you did not receive a copy of the license and are unable to