Menu
  • HOME
  • TAGS

How to customize individual field in collection, symfony 2

php,symfony2,symfony-2.1,symfony-2.3

Correct is: _a_b_cs_entry_widget ...

symfony2 custom input name

rest,symfony2,symfony-2.3

Solution found: Empty the value returned by "UserType::getName()" will remove the prefixes of parameters. Hence "company_mybundle_user[lastName]" becomes lastName Before: // src/Company/MyBundle/Form/UserType.php // ... public function getName() { return 'company_mybundle_user'; } After: // src/Company/MyBundle/Form/UserType.php // ... public function getName() { return ''; } PS: make sure to clear cache before testing:...

How to get doctrine from abstract class in Symfony2?

symfony2,doctrine2,doctrine,symfony-2.3

In order to send data from doctrine to your form, you need to do this into your controller: public function doSomethingWithOneObjectAction( $id ) { $em = $this->getDoctrine()->getManager(); $entity = $em->getRepository( 'AcmeBundle:ObjectEntity' )->find( $id ); if ( ! $entity) { throw $this->createNotFoundException( 'Unable to find Object entity.' ); } $form =...

Call service when pressing a button

twitter-bootstrap,symfony-2.3

You can use Javascript to launch an ajax request when clicking the close button. Here it is in jQuery: $(".close").click(function(){ $.ajax({ url: 'your-url.php', type: 'post', data: {}, success: function (data) { alert('done!') } }); }); That way you can your page will not reload but you will be able to...

How to get file from form in Symfony2?

php,forms,symfony2,symfony-2.3

When you set up your form and entity right symfony will handle it automatically. Example set up: Entity (Document has a file) <?php namespace Acme\DemoBundle\Entity\Document; use Symfony\Component\HttpFoundation\File\UploadedFile; class Document { /** * @var UploadedFile */ protected $file; /** * @param UploadedFile $file - Uploaded File */ public function setFile($file) {...

Write logs in symfony using Monolog

php,symfony2,logging,symfony-2.3,monolog

You're running out of memory trying to process the array. That could be for many reasons, maybe it's just too big, maybe it has recursive aspects, etc. A good trick when working with this is to just print the keys. You will see less data, but you will be much...

Symfony change validation message globally

php,symfony2,symfony-2.3

The easiest way is to define an translations file. # app/Resources/translations/validators.es.yml This value should not be blank.: Campo obligatorio This value is not a valid email address.: e-mail no válido ...

Discriminator on referenced id

symfony2,doctrine2,symfony-2.3

I've found the solution to my problem. These are the doctrine YML files. You can generate all entities with php app/console doctrine:generate:entities AppBundle/Entity. Make sure that the PageTextImageElement class extends the PageElement class. Page.orm.yml AppBundle\Entity\Page: type: entity table: null repositoryClass: AppBundle\Repositories\PageRepository manyToMany: pageElements: targetEntity: PageElement cascade: ["all"] joinTable: name: null...

What is the symfony deubg toolbar trying to tell me?

symfony2,symfony-2.3

Solved the problem. I changed the $type to $model in Model Entity

Server send a image as response and rename it before serving - Symfony 2

php,symfony2,http-headers,symfony-2.3

Symfony2 has a helper for this. This is from the documentation. use Symfony\Component\HttpFoundation\ResponseHeaderBag; $d = $response->headers->makeDisposition( ResponseHeaderBag::DISPOSITION_ATTACHMENT, // disposition 'foo.pdf' // filename ); $response->headers->set('Content-Disposition', $d); ...

Replace object for null in form symfony2

forms,validation,symfony2,doctrine2,symfony-2.3

That's because UniqueEntity constraint validator, which treats null's as duplicates. Create your own validator service and do checks there.

Verify if user is authentificated in symfony2

php,symfony2,symfony-forms,symfony-2.1,symfony-2.3

There are several ways to check if user is authenticated. One would be with app.user as you tried, like this: {% if app.user is not empty %} That will check if your user object is populated with data. You can also use is_granted(). {% if is_granted('IS_AUTHENTICATED_FULLY') %} - Update -...

Can't get the logout action sonata-project

php,symfony2,symfony-2.3,symfony-security

Try to add this on the top of your access_control : - { path: ^/logout$, role: IS_AUTHENTICATED_ANONYMOUSLY } Also, you have to add the target for the logout (where the user will be redirected : logout: path: project_frontend_main_logout target: / #or a specific public route If none of this works,...

Symfony 2 - How to set relationship between three entities having many to many relationship among them

php,orm,doctrine2,symfony-2.3

You need to create separate association table for this relationship. Your ORM file will be like: Application\Bundle\Entity\nameofAssociationTable: type: entity table: nameofAssociationTable fields: id: type: integer id: true generator: strategy: AUTO manyToOne: user: targetEntity: Application\Bundle\Entity\User cascade: { } mappedBy: null inversedBy: null joinColumns: user_id: referencedColumnName: id orphanRemoval: false portfolio: targetEntity: Application\PLibBundle\Entity\Portfolio...

Change theme(css) for SonataAdminBundle

twitter-bootstrap,symfony2,sonata-admin,symfony-2.3,symfony-sonata

You may override the standard_layout.html.twig template file to use your custom theme, as well as all layouts from the SonataAdminBundle. Those files are configurable here: sonata_admin: templates: layout: SonataAdminBundle::standard_layout.html.twig ajax: SonataAdminBundle::ajax_layout.html.twig list: SonataAdminBundle:CRUD:list.html.twig show: SonataAdminBundle:CRUD:show.html.twig edit: SonataAdminBundle:CRUD:edit.html.twig history: SonataAdminBundle:CRUD:history.html.twig preview: SonataAdminBundle:CRUD:preview.html.twig delete:...

Symfony 2 - Symfony CMF SearchBundle instalation

php,search,symfony-2.3,symfony-cmf,doctrine-phpcr

What exactly do you want to do? Do you want to search in a doctrine orm? Then this bundle is not ready for you. Right now, all it supports is searching in Doctrine PHPCR-ODM databases for documents that implement the RouteReferrersReadInterface from the CmfRoutingBundle (this might be something interesting for...

Is there any way to find out the current username from the Symfony2 AppKernel.php?

php,symfony2,symfony-2.3

The Appkernel gets loaded again everytime the user reloads the page, So after the user logs in, set the current user session variable // logincontroller $_SESSION['username'] = $this->getUser()->getUsername(); //since the page gets reloaded on login, you can access it from the AppKernel session_start(); if(isset($_SESSION['username'])) { $username = $_SESSION['username']; read_stuff_from =...

Should I edit the appkernel to use a Core controller

php,symfony2,architecture,symfony-2.1,symfony-2.3

The kernel itself has nothing to do with the controller. That's all handled by the ControllerResolver. If you always want to handle each incomming request using the same controller, you can create your own ControllerResolver to Always return an instance of that controller. See http://symfony.com/doc/current/components/http_kernel/introduction.html#resolve-the-controller for more information about controller...

Query Builder with join and condition in Many to many relation

php,symfony2,doctrine2,doctrine,symfony-2.3

You need to add a JoinTable for your ManyToMany association and set the owning and inverse sides: /** * @ORM\ManyToMany(targetEntity="PFE\EmployeesBundle\Entity\MembreFamille", * cascade={"persist"}, mapped="employees") */ private $membreFamilles; ................................. /** * @ORM\ManyToMany(targetEntity="PFE\UserBundle\Entity\Employee", cascade={"persist"}, inversedBy="membreFamilles") * @ORM\JoinTable(name="membre_familles_employees") */ private $employees; ...

Symfony 2: Two step (not two-factor) authentication

symfony2,authentication,authorization,symfony-2.3

I found somebody with a similar problem, and he received a solution I could use: Symfony 2 : Redirect a user to a page if he has a specific role The event listener class: namespace Acme\DemoBundle\Lib; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpKernel\HttpKernel; use Acme\DemoBundle\Entity\User; class TermsAndConditionsRequestListener { private $security; private...

Login system in symfony 2

php,symfony2,symfony-2.1,symfony-2.3,php-5.4

I think the problem is, that you haven't updated your user providers In security.yml you still have a static list of users provided by the in_memory user provider. The security system is not aware of your own class ShopDesktopBundle:Customer. If you follow the cookbook on "How to Create a custom...

Using the container inside a simple bundle class dont work in Symfony 2

php,symfony2,dependency-injection,symfony-2.3

You need to pass the container to your service, below an example how to do it in your services.yml services: srv_grafica: class: Agc\ManagerBundle\Lib\grafica arguments: - '@service_container' ...

Override ProfileController FOSUserBundle in Symfony 2.3

symfony2,symfony-2.3

The FOSUserBundle-RegistrationController doesn't extend SF2's Symfony\Bundle\FrameworkBundle\Controller\Controller which provides the render() method. It just implements ContainerAware interface. Which error do you get when calling $this->container->get('templating')->renderResponse()?...

Symfony2 : Entity Field Type Saves Zero

php,symfony2,symfony-2.1,symfony-2.3,symfony2.4

Solved ! For other friends who may have the same problem, I explain it here : The error was in my entity relationship mapping. I followed this documentation : http://symfony.com/doc/current/book/doctrine.html#relationship-mapping-metadata and changed annotations and yml configs, then executed this command line : php app/console doctrine:generate:entities Acme Now it works fine...

How to set styles for checkboxes in Symfony2?

symfony2,checkbox,twig,symfony-2.3

You can change the way the checkboxes are rendered in several ways. I'm going to show you the easiest one (in the example, I assume form.colors as the variable that holds the choice element): <div class="" style="display: inline-block;"> {% for color in form.colors %} <label class="check"> {{ form_errors(color) }} {{...

return array of objects by foreign key from database table

php,doctrine2,symfony-2.3

Seems you have an association like this: /** * @ORM\ManyToOne(targetEntity="Post") */ protected $post; So you should find your comments by post, not by post_id: $comments = $this->get('doctrine')->getRepository('BlogCommonBundle:Comment')->findBy(['post' => $postID]); And you can also sort it just by adding ['created' => 'DESC'] as a second parameter: $comments = $this->get('doctrine')->getRepository('BlogCommonBundle:Comment')->findBy(['post' => $postID],...

Symfony CRUD generator with Bootstrap 3 support?

php,symfony2,twitter-bootstrap-3,crud,symfony-2.3

I used to have to perform my own form modifications as well. However, Symfony 2.6 introduces support for Bootstrap 3.0 for forms: http://symfony.com/blog/new-in-symfony-2-6-bootstrap-form-theme So if you upgrade to Symfony 2.6 you should have that built in....

symfony2 how to store session differently on one domain/IP with to different application

php,session,fosuserbundle,symfony-2.3

You probably should configure both projects to use different place where session files are stored. In Symfony2 you can do that with save_path param in framework configuration More info: http://symfony.com/doc/current/cookbook/session/sessions_directory.html Also it can be done strictly in PHP with session_save_path function. Edit. Also changing just session name could work too....

Symfony + doctrine : select clause where don't work

php,symfony2,doctrine2,doctrine,symfony-2.3

You can always debug the actual SQL Doctrine is calling by executing $qb->getQuery()->getSQL() where $qb is your QueryBuilder object, or by looking at the Symfony toolbar. There's two issues with the code. Firstly, the definition of the $isActive field is wrong, it should be a boolean rather than a simple_array:...

Update session in symfony2 for shoppingg cart

php,symfony2,symfony-2.1,php-5.3,symfony-2.3

You can simplify your code to, i guess your session array would look something like array( '11' =>array('id'=>'11','title'=>'some product','product_quantity'=>2), '12' =>array('id'=>'12','title'=>'some product','product_quantity'=>1), '13' =>array('id'=>'13','title'=>'some product','product_quantity'=>3), ); key in your cart array will be product id so there will be no chance of duplicate product in array now in below code...

Execute an action right after the user confirms registration

symfony2,symfony-2.3

You can create an EventListener which listens for FOSUserEvents::REGISTRATION_CONFIRMED like this: use Symfony\Component\EventDispatcher\EventSubscriberInterface; use FOS\UserBundle\FOSUserEvents; use FOS\UserBundle\Event\UserEvent; class RegistrationConfirmedEventListener implements EventSubscriberInterface { public static function getSubscribedEvents() { return array(FOSUserEvents::REGISTRATION_CONFIRMED => 'performOnRegistrationConfirmed'); } public function performOnRegistrationConfirmed(UserEvent $event) { $user =...

Running more than one console commands in a controller Symfony 2

symfony2,symfony-2.3,symfony2.4

First of all I need to thank @vincecore to giving me the heads up regarding Symfony Process Component. I managed to workaround with Process component to achieve what I wanted to achieve. I assume kernel boot shutdown is not a proper approach even though it works well. However generate form...

Error trying flush an object in the database with Symfony2

symfony2,doctrine2,symfony-2.3

You’re doing the mapping in Content.php in the wrong way. If you’re setting a ManyToOne relation with the Category Entity, you should have a $category and not a $category_id attribute. You should deal with objects, and not integers. Therefore, your Content Entity should look like this: <?php // Jjj\SomeBundle\Entity\Content.php /**...