FAQ Database Discussion Community


Update session in symfony2 for shoppingg cart

php,symfony2,symfony-2.1,php-5.3,symfony-2.3
I have the following code : public function addAction(Request $request){ //Get submited data // Get Value from session $sessionVal = $this->get('session')->get('aBasket'); // Append value to retrieved array. $aBasket = $request->request->all(); if(count($sessionVal) > 0) { foreach ($sessionVal as $key=>$value) { if($aBasket['product_id'] == $sessionVal[$key]['product_id']) { $sessionVal[$key]['product_quantity'] = $sessionVal[$key]['product_quantity'] + $aBasket['product_quantity'];...

Login system in symfony 2

php,symfony2,symfony-2.1,symfony-2.3,php-5.4
I tried to create an authentification system in symfony2 but no results. In the debug status bar for all situations I have : Logged as anon. If I make a dump of session in the view I get : "_security.last_error" => BadCredentialsException My routing file: shop_show_login_page: path: /login defaults: {...

Write logs in symfony using Monolog

php,symfony2,logging,symfony-2.3,monolog
I have a problem with my project, I want to use Monolog to write the logs and I can't do. So, I created an service : services: my_logger: class: Monolog\Logger arguments: [Debug] calls: - [pushHandler, [@my_log_handler]] my_log_handler: class: Monolog\Handler\StreamHandler arguments: [/home/vagrant/Workspace/symfony/app/logs/test.log, 100] My controller : $em = $this->getDoctrine()->getManager(); $categories =...

How to set styles for checkboxes in Symfony2?

symfony2,checkbox,twig,symfony-2.3
I have problem with checkboxes which I render by FormBuilder. The problem is that <input/> is generated inside <label></label>. The result is the following: I don't know what I should do to format this checkboxes to the state on the right side of the image. I check documentation and I...

What is the symfony deubg toolbar trying to tell me?

symfony2,symfony-2.3
What is the debugger trying to tell me from that red notification in the toolbar? When i clicked it, it showed me some papping errors. Why is it an error? Category Entity <?php namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; /** * Category * * @ORM\Table(name="ewaste_category") * @ORM\Entity *...

Symfony change validation message globally

php,symfony2,symfony-2.3
Is there a way to change the basic validation error message to one I need for all entities at once? Currently using Yaml config for every entity, but it's not a way. CF\MyBundle\Entity\User: properties: email: - Email: message: e-mail no vĂ¡lido - NotBlank: message: Campo obligatorio username: -NotBlank: message: Campo...

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

php,symfony2,dependency-injection,symfony-2.3
My Error: ContextErrorException: Catchable Fatal Error: Argument 1 passed to Agc\ManagerBundle\Lib\grafica::__construct() must implement interface Symfony\Component\DependencyInjection\ContainerInterface, none given, called in C:\wamp\www\galileo\src\Agc\BackendBundle\Controller\DefaultController.php on line 20 and defined in C:\wamp\www\galileo\src\Agc\ManagerBundle\Lib\grafica.php line 10 My class grafica: <?php namespace Agc\ManagerBundle\Lib; use Symfony\Component\DependencyInjection\ContainerInterface; /** *...

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

php,session,fosuserbundle,symfony-2.3
I have two different projects in symfony2. I am using symfony2.3 version. I have used fosuserbundle for user authentication. I have one server. I have uploaded my both projects at /var/www/html/project1 /var/www/html/project2 And i am accessing my two applications/projects like http://202.12.0.0/project1 and http://202.12.0.0//project2. (IP here is given only for example....

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

php,orm,doctrine2,symfony-2.3
I am using Symfony2 for my application and using Doctrine .orm.yml files for relation mapping. I have three entities as follows: user entity which contains id(integer primary key), user_name(varchar) portfolio entity which contains id(integer primary key), name(varchar), user_id (FK from user to identify who created the portfolio) progress entity which...

Can't get the logout action sonata-project

php,symfony2,symfony-2.3,symfony-security
This is my security.yml file firewalls: main: pattern: ^/ form_login: provider: fos_userbundle csrf_provider: form.csrf_provider login_path: project_frontend_main_index logout: path: project_frontend_main_logout anonymous: true access_control: - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } - { path: ^/admin/, role: ROLE_ADMIN }...

How to get doctrine from abstract class in Symfony2?

symfony2,doctrine2,doctrine,symfony-2.3
In my code I need to download from database some data and put it to the form, but I don't know how to get doctrone outside Controller class. I tried create new service, but it didn't work (I think I can't use in this case __controller(), am I right?). I...

Query Builder with join and condition in Many to many relation

php,symfony2,doctrine2,doctrine,symfony-2.3
I have a many to many relation with Employee and MembreFamille. And i want to get all MembreFamilles that have an Employee. This is my query : class MembreFamilleRepository extends EntityRepository { public function getMembres($emp) { $qb = $this->createQueryBuilder('a'); $qb ->leftJoin('a.employees', 'employees'); $qb ->where('employees.id = :id') ->setParameter('id', $emp); return $qb...

Verify if user is authentificated in symfony2

php,symfony2,symfony-forms,symfony-2.1,symfony-2.3
I tried to create a simple login application in symfony2 and I don't understand a thing. My routing file : shop_show_login_page: path: /login defaults: { _controller: ShopDesktopBundle:User:loginPage } shop_login_user: path: /loginUser defaults: { _controller: ShopDesktopBundle:User:loginCheck } My controller with this 2 methods : public function loginPageAction(){ return $this->render('ShopDesktopBundle:User:loginPage.html.twig'); } public...

Symfony 2 - Symfony CMF SearchBundle instalation

php,search,symfony-2.3,symfony-cmf,doctrine-phpcr
I'm trying to install Symfony CMF SearchBundle over a clean Symfony 2.3 but the installation instructions are quite incomplete. It seems like it has some dependencies that needs to be added manually in composer.json. After hours I got to this: "jackalope/jackalope-doctrine-dbal": "1.1.2", "jackalope/jackalope": "1.1.7", "doctrine/phpcr-odm": "1.2.*", "doctrine/phpcr-bundle": "1.2.*", "symfony-cmf/routing-bundle": "1.3.3",...

How to get file from form in Symfony2?

php,forms,symfony2,symfony-2.3
I have form with File Field Type. I would like to "catch" uploaded file in controller but I don't know how to do it. I tried to get access via $form->get('file'), but seems to me that this is the wrong way to go. Why? var_dump( $form->get('file') ); return string with...