Symfony Forms: HTML5 datalist

First, add your new FormType for the field:. <?php // src/Acme/Form/Type/DatalistType namespace Acme\Form\Type; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; class DatalistType extends AbstractType { public function getParent() { return TextType::class; } public function configureOptions(OptionsResolver $resolver) { $resolver->setRequired([‘choices’]); } public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars[‘choices’] = $options[‘choices’]; } … Read more

How can I use DATE() in Doctrine 2 DQL?

In addition to the accepted answer there are a tonne of pre-built custom functions available at https://github.com/beberlei/DoctrineExtensions . These can be then registered in your config like doctrine: orm: dql: string_functions: DATE: DoctrineExtensions\Query\Mysql\Date and can then be used in your DQL (as in your query) like DATE(jobs.endDate) AS endDate

Get entityManager inside an Entity

As pointed out (again) by a commenter, an entity manager inside an entity is a code smell. For the OP’s specific situation where he wished to acquire the entity manager, with the least bother, a simple setter injection would be most reliable (contrary to my original example injecting via constructor). For anyone else ending up … Read more

Limiting a doctrine query with a fetch-joined collection?

Paginate was merged with doctrine 2.2 And the new symfony2 release 2.0.10 is compatible with. Now use it like that //use Doctrine paginator use Doctrine\ORM\Tools\Pagination\Paginator; Write your query then call results like that. $query->setMaxResults($limit); $query->setFirstResult($offset); $results = new Paginator($query, $fetchJoin = true); Hope this will help you. Note: If you are using SF2 2.0.10, you … Read more

PHP ORMs: Doctrine vs. Propel

I’d go with Doctrine. It seems to me that it is a much more active project and being the default ORM for symfony it is better supported (even though officially the ORMs are considered equal). Furthermore I better like the way you work with queries (DQL instead of Criteria): <?php // Propel $c = new … Read more

Use a DATE() function in a WHERE clause with DQL

You can achieve what you want by using a custom function: use Doctrine\ORM\Query\AST\Functions\FunctionNode; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\SqlWalker; use Doctrine\ORM\Query\Parser; class DateFunction extends FunctionNode { private $arg; public function getSql(SqlWalker $sqlWalker) { return sprintf(‘DATE(%s)’, $this->arg->dispatch($sqlWalker)); } public function parse(Parser $parser) { $parser->match(Lexer::T_IDENTIFIER); $parser->match(Lexer::T_OPEN_PARENTHESIS); $this->arg = $parser->ArithmeticPrimary(); $parser->match(Lexer::T_CLOSE_PARENTHESIS); } } Then registering this function in your code: … Read more

Can I access discriminator field from php in doctrine2?

Extending what beberlei said, you could declare some constants in the Attribute class, and an abstract getType() function. Then, overload it in every derived attribute class. Something like: abstract class Attribute { const TYPE_BOOL = 0; const TYPE_INT = 1; … abstract public function getType(); } class BooleanAttribute extends Attribute { public function getType() { … Read more

php/symfony/doctrine memory leak?

Tried doing $cupo->save(); $cupo->free(); $cupo = null; (But substituting my code) And I’m still getting memory overflows. Any other ideas, SO? Update: I created a new environment in my databases.yml, that looks like: all: doctrine: class: sfDoctrineDatabase param: dsn: ‘mysql:host=localhost;dbname=…….’ username: ….. password: ….. profiler: false The profiler: false entry disables doctrine’s query logging, that … Read more