symfony-2.1

Authentication in functional tests in Symfony 2.1

落爺英雄遲暮 提交于 2019-11-27 10:23:28
问题 I am currently in the process of migrating a 2.0.* project to the current 2.1 beta of Symfony. In my functional tests i currently have this code to create a client with authentication: $client = // create a normal test client $role = 'ROLE_USER'; $firewallName = 'main'; $user = // pull a user from db $client->getCookieJar()->set(new \Symfony\Component\BrowserKit\Cookie(session_name(), true)); $token = new UsernamePasswordToken($user, null, $firewallName, array($role)); self::$kernel-

doctrine2 findby two columns OR condition

送分小仙女□ 提交于 2019-11-27 07:55:10
问题 My action: $matches_request = $em->getRepository('Bundle:ChanceMatch')->findByRequestUser(1); $matches_reply = $em->getRepository('Bundle:ChanceMatch')->findByReplyUser(1); Is it possible to join the querys with an or condition with getRepository, eg. $matches_reply = $em->getRepository('FrontendChancesBundle:ChanceMatch')->findBy(array('requestUser' => 1, 'replyUser' => 1); //this of course gives me the a result when `requestUser` and `replyUser` is `1`. My table id | requestUser | replyUser

Autoloading a class in Symfony 2.1

不想你离开。 提交于 2019-11-27 07:46:52
问题 I'm porting a Symfony 1.2 project to Symfony 2.x. I'm currently running the latest 2.1.0-dev release. From my old project I have a class called Tools which has some simple functions for things like munging arrays into strings and generating slugs from strings. I'd like to use this class in my new project but I'm unclear how to use this class outside of a bundle. I've looked at various answers here which recommend changing app/autoload.php but my autoload.php looks different to the ones in the

Set locale in Symfony 2.1

隐身守侯 提交于 2019-11-27 05:43:48
问题 I am trying to have a language switcher on my symfony 2.1 website. I followed the official documentation, set the translation files but setting the locale with $request->setLocale('en_US'); doesn't seem to work. After some research, I found this question which provides a beginning of an answer with this listener technique. However, I still don't manage to have it working, I'm not so sure about my listener declaration, is something wrong with it? My controller: public function englishAction

Set default value on Datetime field in symfony2 form

巧了我就是萌 提交于 2019-11-27 03:01:37
问题 I have a form containing several fields. One of them is a Datetime field. How to define a default value for that field? I've tried setting a value on the related entity, in controller, in constructor and __construct : $myEntity = new MyEntity(); $myEntity->setMyDate(new \DateTime()); $form = $this->createForm(new AddMyEntity(), $myEntity); Not working. Tried to define the $data variable in the buildForm : $builder->add('myDate', 'date', array( 'format' => \IntlDateFormatter::SHORT, 'input' =>

Symfony2.1 using form with method GET

倖福魔咒の 提交于 2019-11-27 02:53:45
问题 I need help on using Symfony2.1 forms with method=GET and a clean URL space. I am creating a "filter" which I'd like to set in the URL so that people can bookmark their links. So, very simply the code: $form = $this->createFormBuilder($defaultData) ->add('from', 'date', array('required' => false, 'widget' => 'single_text', 'format' => 'dd.MM.yyyy')) I render the form widget and all is fine. However when I submit the form, it produces very ugly GET parameters: /app_dev.php/de/event?form%5Bfrom

How can I add a violation to a collection?

▼魔方 西西 提交于 2019-11-27 02:53:24
问题 My form looks like this: public function buildForm(FormBuilderInterface $builder, array $options) { $factory = $builder->getFormFactory(); $builder->add('name'); $builder->add('description'); $builder->add('manufacturers', null, array( 'required' => false )); $builder->add('departments', 'collection', array( 'type' => new Department )); } I have a class validator on the entity the form represents which calls: if (!$valid) { $this->context->addViolationAtSubPath('departments', $constraint-

How would you add a file upload to a Symfony2 DataFixture?

五迷三道 提交于 2019-11-27 02:19:09
问题 I can't seem to wrap my head around how I would go about adding a file upload to a DataFixture. I'm trying to upload an image for the dummy content my fixtures load. This seems like something that would be useful to know. 回答1: Although this question has been asked 1 year ago it appears that there is not a lot of information out there on how to upload a file via doctrine data fixture. I could only find this post. I've been looking and I've taken a slightly different approach than ornj's.

Symfony 2.1 set locale

妖精的绣舞 提交于 2019-11-27 01:59:57
问题 Does anybody know how to set the locale in Symfony2.1? I am trying with: $this->get('session')->set('_locale', 'en_US'); and $this->get('request')->setLocale('en_US'); but none of those has any effect, the devbar tells me: Session Attributes: No session attributes Anyway, it is always the fallback locale that is used, as defined in config.yml (PS: I am trying to set up the translation system as described here 回答1: Even though the Symfony 2.1 states that you can simply set the locale via the

Sonata Admin Bundle: DatePicker range

本小妞迷上赌 提交于 2019-11-27 01:33:21
问题 How would I create a doctrine_orm_datetime_range filter in the Sonata Admin Bundle which uses the jQuery UI datepicker? I tried the following, but it doesn't work: protected function configureDatagridFilters(DatagridMapper $datagridMapper) { $datagridMapper ->add('datumUitgevoerd', 'doctrine_orm_datetime', array('widget' => 'single_text'), null, array('required' => false, 'attr' => array('class' => 'datepicker'))) ; } 回答1: UPDATED 2016-02-02 If you are using 3.* Symfony the following twig