symfony-2.1

How can I use efficiently paginate with doctrine in Symfony 2?

我怕爱的太早我们不能终老 提交于 2019-12-07 06:50:26
问题 I would like to use Doctrine ORM and a pagination method in Symfony. KnpPaginatorBundle looks simple and easy to use. I also use Doctrine repositories because the queries can be easily reused and tested. This bundle works like others I found. It needs the query builder as parameter. Is there a better way to do this than giving each repository function the paginator as a parameter (or null)? I do not want to paginate every query result so I do not think that the described solution is the best

Symfony2 authenticating users through a webservice

依然范特西╮ 提交于 2019-12-07 06:24:30
问题 I'm currently dealing with Symfony2's Security component. I try to authenticate users against a webservice. To authenticate a user, I have to provide to the webservice a username and a password. I know that I've got to create a class that implements UserProvider. But the loadUserByUsername function doesn't fit my webservice needs : in order to authenticate a user, it ask for both username and password whereas the UserProvider's function only requires username. Here is a similar question to

Assetic files in symfony are behind the firewall?

守給你的承諾、 提交于 2019-12-07 04:42:38
问题 I have simple login page and security set up like this: firewalls: main: pattern: ^/ form_login: provider: fos_userbundle csrf_provider: form.csrf_provider use_referer: true always_use_default_target_path: true default_target_path: / logout: true anonymous: true access_control: - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/, role: ROLE_ADMIN } And in my

symfony2.1 bundle version confusion, for symfony and sonata admin / knp menu bundle

谁说我不能喝 提交于 2019-12-07 03:45:03
问题 I want to use symfony2.1 for a new project. I try to install symfony2 with composer. But there were multiple errors/problems and so I have also questions for each problem in bold font style . Sometimes I don't know if I do it the right way. I want to use a stable version so I chosen the 2.1.0 version and not the dev/master. php composer.phar create-project symfony/framework-standard-edition symfony v2.1.0 the result was this: Installing symfony/framework-standard-edition (v2.1.0) - Installing

Login programmatically and stay logged in

寵の児 提交于 2019-12-07 01:37:03
问题 I'm trying to implement single sign on access to a website using Symfony2. The authentication itself seems to work fine, but only for the initial page. On the next page that is loaded the user is not logged in anymore. Relevant code: $token = new UsernamePasswordToken($user, null, 'main', $user->getRoles()); $event = new InteractiveLoginEvent($request, $token); $this->get("event_dispatcher")->dispatch(SecurityEvents::INTERACTIVE_LOGIN, $event); $this->get("security.context")->setToken($token)

Option groups in symfony2 entity form type

谁说胖子不能爱 提交于 2019-12-06 16:09:46
Is there any way an entity field can be shown grouped in option groups in symfony2 (v.2.1), for example I have something like this in my form class: $builder->add('account', 'entity', array( 'class' => 'MyBundle\Entity\Account', 'query_builder' => function(EntityRepository $repo){ return $repo->findAllAccounts(); }, 'required' => true, 'empty_value' => 'Choose_an_account', ); But (of course) they are displayed as the repository class reads it from the db and I would like to display them grouped in the combobox. This post mentions that featured added to the 2.2 release out of the box, but what

pagination in symfony 4 using KnpPaginatorBundle

余生颓废 提交于 2019-12-06 15:19:43
Attempted to load class " KnpPaginatorBundle " from namespace " App\Knp\Bundle\PaginatorBundle ". Did you forget a " use " statement for " Knp\Bundle\PaginatorBundle\KnpPaginatorBundle "? Just add class namespace of KnpPaginatorBundle : in config/bundles.php : <?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], *************************************************************** *************************************************************** Knp\Bundle\PaginatorBundle\KnpPaginatorBundle::class => [

Symfony Form Class: rename fields name attribute's value

丶灬走出姿态 提交于 2019-12-06 13:35:27
问题 Is there a way to set individual form fields name in the FormBuilder? What I mean is normally you get is form_name[field_name] , or if the form_name is an empty string you get field_name . Now I want to ask if it is possible to rename individual field name and the form still works. Something like this: First field name="form_name[field_name]" Second field name="renamed_fildname" Third field name="form_name[field_name]" etc... So is this possible? More explanation: this is what I am trying to

Form does not display form errors in template

只愿长相守 提交于 2019-12-06 12:37:29
问题 For my contact form no form errors are displayed. $contact = new Contact(); $form = $this->createForm(new ContactFormType(), $contact); /* handle contact form submission */ if ('POST' == $request->getMethod()) { $form->bindRequest($request); if ($form->isValid()) { //Do something } } return $this->render('MainBundle:Default:contact.html.twig', array( 'form' => $form->createView() )); My validator Fc\MainBundle\Entity\Contact: properties: firstName: - NotBlank: ~ lastName: - NotBlank: ~ email:

With Symfony2 why are ESI tags inside cached responses ignored?

旧街凉风 提交于 2019-12-06 10:21:33
问题 I have an ecommerce application that I'm try to set up for caching - initially via the Symfony2 Reverse Proxy, but then ultimately via Varnish in production. I'm using Symfony 2.1.8 on Apache2. My problem is I cannot get the ESI tags to be re-checked for each request when the primary controller action is cached (important for private content like the basket contents), but I don't understand why. For example, I cache the homepage with the following code: public function indexAction(Request