Monthly Archives: July 2012

Symfony2: Using DBAL in repository classes

<?php namespace Companyname\TEstbundle\Repository; use Doctrine\ORM\EntityRepository; use Doctrine\ORM\NoResultException; class TestRepository extends EntityRepository { private $oDBALConnection; public function __construct($em, $class) { parent::__construct($em, $class); $this->oDBALConnection = $this->getEntityManager()->getConnection(); } /** * * @param type $date_from * @param type $date_to * @return type */ public … Continue reading

Posted in Uncategorized | 2 Comments

Symfony2, DBAL, Doctrine2: create SQL IN Operator from PHP array

$aAccountCode = array(‘blabla1’, ‘accouncode1111’); $oDBALConnection = $this->get(‘database_connection’); $stmt = $oDBALConnection->executeQuery(‘SELECT * FROM table_name WHERE resource_name IN (?)’, array($aAccountCode), array(\Doctrine\DBAL\Connection::PARAM_STR_ARRAY) ); $stmt->execute(); $aAccountID = $stmt->fetchAll( \PDO::FETCH_COLUMN);

Posted in array, DBAL, doctrine2, IN, Symfony2 | Leave a comment

Symfony2 command line and Doctrine

<?php namespace ProjectName\TestBundle\Command; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use PDO; class TestCommand extends ContainerAwareCommand { protected $em = NULL; protected function configure() { $this ->setName(‘testcommandlineapp’) ->setDescription(‘Blabla’) ->setDefinition(array()); } protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln( ‘Working…’ … Continue reading

Posted in CommandLine, Doctrine, Symfony2 | Leave a comment

Symfony2: disable CSRF protection on form

$document = new Document(); $form = $this->createFormBuilder($document, array(‘csrf_protection’ => false)) ->add(‘name’) ->add(‘file’) ->getForm(); if ($this->getRequest()->getMethod() === ‘POST’) { $form-bindRequest($this->getRequest()); //validation form if ($form->Valid()) { …..  It’s easy ūüėČ

Posted in CSRF, disable, form, Symfony2 | Leave a comment

Symfony2: validator collection in controller

public function ajaxDatePickerAction( Request $request) { $collectionConstraint = new Collection(array( ‘date_from’ => array( new NotBlank(), //date cannot be blank new Date(), //standard Symfony2 Date validator ), ‘date_to’ => array( new NotBlank(), new Date(), ) )); $formInputData = array( ‘date_from’ => … Continue reading

Posted in Uncategorized | Leave a comment