symfony-2.1

Doctrine2 - is there a pre-selection hook?

半世苍凉 提交于 2019-12-11 13:49:25
问题 I'm developing a ws with Symfony2 / Doctrine2, and I'm trying to hook into Doctrine2 lifecycle and trigger a function before any SELECT action - but without any luck. Basically, i'd like to dynamically manipulate the selection queries adding limit/offset when certain parameters are found in the request, but it seems that Doctrine2 hooks concern only insert, delete and update actions. Am i missing something? Thanks. 回答1: U have to use Doctrine Filter Doctrine 2.2 features a filter system that

Form bind not binding request to form in Symfony 2.1+FOSRestBundle

China☆狼群 提交于 2019-12-11 10:59:17
问题 I'm implementing rest API using FOSRestbundle. Now say for POST request i'm getting request parameters properly like: Symfony\Component\HttpFoundation\ParameterBag Object ( [parameters:protected] => Array ( [rank] => 12 [city] => 1345 [comment]=> 'safd' ) ) My post action code is : /** * @Rest\View */ public function newAction(){ $rank= new Rank(); $form = $this->createForm(new RankType(), $rank); $form->bind($this->getRequest()); if ($form->isValid()) { //. $user->flush(); $em = $this-

How can I pass a parameter to a Doctrine2 custom function in the Query Builder select() method?

假装没事ソ 提交于 2019-12-11 08:46:11
问题 In my Symfony2 project I am retrieving an ordered set of entity IDs from an Elasticsearch index. I'm then passing this list to Doctrine2 to retrieve the actual entities, by way of a WHERE IN() call. This doesn't return them in the correct order, so I think I need to use the MySQL-specific FIELD() function. I've created a custom DQL function to allow the functionality. So now I'm using the following code to build a Doctrine query object, but the parameters aren't being parsed into the select()

Symfony 2.1. How can I display a single_text time field in 12 hour am/pm format?

感情迁移 提交于 2019-12-11 03:07:12
问题 I have a time field on my form with widget set to 'single_text'. My US users will want 12 hour am/pm format. http://symfony.com/doc/current/reference/forms/types/time.html#widget Although it's not entirely obvious, that accepts an input of 2:15pm but if the form returns because of a validation error on another field or is later opened to edit an existing record then it displays 14:15 which of course is correct but is probably off-putting. How do I get it to display 2:15pm? I don't see an

Change html lang attribute when locale changes

主宰稳场 提交于 2019-12-11 02:41:48
问题 I have a multilangual website running with PHP/Symfony2. I would like to change the html lang attribute when the user switches language (= switching locale). What is the best way to achieve this? PS: my ultimate goal is to be able to switch font for different languages (chinese looks just too bad with the font I chose for english). I am thinking of using the CSS :lang() pseudo selector: html:lang(zh) 回答1: Asuming you are using html5 and twig as template engine: <!doctype html> <html lang="{{

Symfony2 A session had already been started - ignoring session_start()

我只是一个虾纸丫 提交于 2019-12-11 01:58:08
问题 I can't use Symfony2 session in my local server. I'm getting a "Notice: A session had already been started - ignoring session_start()" error. Same script works fine in my production server. I'm using Xampp with PHP 5.3.5 over Windows 7. Session auto_start is off in php.ini. Any hint will be helpfull. Thanks 回答1: I guess it's a bite late but if it can help: Make sure your session.autostart is turned off (0) in your php.ini The way to use the session in Symfony 2 from the controler is the

Symfony 2 upgrade to 2.1: LogicException: Container extension “security” is not registered

不羁岁月 提交于 2019-12-10 19:38:04
问题 Just upgrading to Symfony 2.1. Been following the guides: https://github.com/symfony/symfony-standard/blob/master/UPGRADE.md https://github.com/symfony/symfony/blob/master/UPGRADE-2.1.md Everything seemed to go well, but now I keep getting the following exception LogicException: Container extension "security" is not registered I have compared my settings to the lastest available download of Symfony 2.1 and I can't see why the security extension is not registered. Can anyone help me out?

Symfony2 Form Entity to String Transformer Issue

拈花ヽ惹草 提交于 2019-12-10 18:04:30
问题 I am using Symfony 2.1.3-DEV and trying to accomplish transforming entity to string (ID of some kind) and then back from string to entity when form is submitted. The issue is the same if I'm using the transformer given in the cookbook: http://symfony.com/doc/master/cookbook/form/data_transformers.html Controller code: $task = $entityManager->find('AcmeTaskBundle:Task', $id); $form = $this->createForm(new TaskType(), $task); // so $task->issue is Issue object I get this error: The form's view

Error after Upgrading FOS UserBundle from 1.2 to 2.0 in Symfony 2.1

给你一囗甜甜゛ 提交于 2019-12-10 17:34:50
问题 I have a project in Symfony 2.1, with PropelBundle, and FOS UserBundle. I upgraded FOS UserBundle with Composer from 1.2 to the latest version (2.0) and followed the instruction to delete the "propel_user_class" definition in the app/config/config.yml file as indicated in the Upgrade.md file. My new config is as follows: # FOSUserBundle Configuration fos_user: db_driver: propel firewall_name: main user_class: MyVendor\MyBundle\Model\Member registration: form: type: myvendor_user_registration

validation on unbound form field

被刻印的时光 ゝ 提交于 2019-12-10 15:39:46
问题 I have a form with an extra unbound field added using 'property_path' => false. I would like to have a simple validation on this field and I've found many answers that suggest to use something like $builder->addValidator(...); but I've seen that in symfony 2.1 $builder->addValidator is deprecated. Does anyone know what is the correct way to put a validation on an unbound field in Symfony 2.1? 回答1: Edit : I've just made a more complete answer on topic Symfony validate form with mapped false