Symfony2: autoload/register namespaces from within a Bundle

I am working on a bundle in which I use the Doctrine CouchDB ODM. How does one autoload and register the namespaces from within a bundle? Here are the relevant working lines from app/autoload.php that I need to move: use Symfony\Component\ClassLoader\UniversalClassLoader; $loader->registerNamespaces(array( // ... 'Doctrine\\CouchDB' => __DIR__.'/../vendor/doctrine-odm/lib', 'Doctrine\\ODM\\CouchDB' => __DIR__.'/../vendor/doctrine-odm/lib', )); Thank you!

Symfony2 Access Controls regex not working

I'm using following Acess Control in security.yml: - { path: ^/g/+/submit, roles: IS_AUTHENTICATED_FULLY } the "+" should make any word match, but it does not work if I try any of the urls like: /g/something/submit /g/somethingelse/submit Are regular expressions not fully working in access controls in symfony2? Is there a workaround?

Symfony Accessing a variable through $options in the buildForm()

I want to pass a boolean to my DogForm $dogForm = new DogForm(null, array("has_cats" => $this->getUser()->hasCats())); $form = $this->createForm($dogForm, $dog); But when doing in my DogForm : if (!isset($options['has_cats'])) { throw new \Exception("Missing option has_cats, this option is mandatory"); } It always give me this error. So i know that dogs aren't supposed to have cats but, where my has_cats option went ? Thanks.

Symfony Circular Reference when injecting Security Context into (Entity Listener) Class

There was 2 questions here saying injecting the whole service container should solve this. But question ... see below (note difference between try 2 & 3) ... Try 1 public function __construct(SecurityContext $securityContext) { $this->securityContext = $securityContext); } Curcular Reference. Okay ... Try 2 public function __construct(ContainerInterface $container) { $this->securityContext = $container->get('security.context'); } Circular Reference (Why?, I

symfony2 : twig extension is_granted('EDIT', comment) doesn't work in a foreach loop

The code of the official ACL example works : If I do that, no problem... {% if is_granted('EDIT', comment) %} Edit {% endif %} ... but if I want a "Granted Access" to an associated object, it doesn't work. {% for comment in news.comments %} comment.content {% if is_granted('EDIT', comment) %} Edit {% endif %} {% endfor %} I think the twig extension can't know that "comment" is a "Comment Entity". The query

Get non-default EM in Symfony2 test

I have a Symfony2 unit test in which I get the entity manager like this: $this->_em = $kernel->getContainer()->get('doctrine.orm.entity_manager'); This works fine for the default entity manager, but I want to get another entity manager called core, which exists in addition to default. How can I do this? I tried this just for kicks and it didn't work: $this->_em = $kernel->getContainer()->get('doctrine.orm.entity_managers.core');

Creating a custom user provider with symfony

I'm trying to do my own custom user provider, but I'm stuck at this part of the Symfony tutorial (Create a User Provider). What do I need to do at the $userdata variable? A database connection? I don't know what I need to do at this place: public function loadUserByUsername($username) { // here // $userData = ... if ($userData) { //here too //$password = ... return new DomixBlogUser($username, $password, $salt, $roles) } else { throw new Userna

Symfony Remove password checking when using user registration form

I want to create user and generate password automatically. I am using custom form class for displaying first name, lastname and email fields. Username is created based on email and there is no issue with this. However i cannot skip password validation and implement password generation when saving new user. Should I create custom validator.xml original one is as follows: <?xml version="1.0" encoding="UTF-8" ?> <container xmlns="" xmlns:xsi="h

Broken paths to images in Symfony2 Dev environment

After succesfully publishing my bundle, dev environment is broken. To publish my assets i did : php console assets:install --symlink --relative /home/bitnami/stack/frameworks/symfony/web php console assetic:dump php console cache:clear --env=prod --no-debug Images are referenced to : /symfony/web/bundles/webprofiler/images/profiler/logo_symfony_profiler.png

Symfony how to disable insert data into DB (FR3DLdapBundle)?

FR3DLdapBundle will insert data into DB, if ldap authentication successes, but no data in DB exists. How can i disable it? I have already an user table with many usernames and roles, and i don't want to insert more data into it throw LdapBundle. Thanks in advance.

Nested prototypes in Symfony2 Configuration

With the Symfony2 TreeBuilder, its possible to configure prototypes for each node inside an array node, e.g. to support a configuration like foo: xxx: { foo: bar} yyy: { foo: bar} Where there are any number of xxx, yyy and so on (any value at all) nodes using a structure like $rootNode ->arrayNode('foo') ->prototype('array') ->children() ->scalarNode('foo') I would like to create another level of the same thing without introducing another nam

Symfony How to validate two instances of the same entity?

I am learning Symfony2 and am creating a Table Tennis tracking app to learn the framework. I have configured my entities as follows. Player 1..n Result n..1 Match On my form I'd like to validate that the scores for a match are correct. Implementation Match has an ArrayCollection() of results. My MatchType and ResultType forms contain the following. // Form\MatchType $builder->add('matchType', 'entity', array( 'class' => 'PingPongMatchesBundle:MatchType',

swiftmailer configuration for more than one accounts in Symfony 2

I use gmail to send mails ,so I config ‘config.yml’ like this swiftmailer: transport: %mailer_transport% encryption: %mailer_encryption% auth_mode: %mailer_auth% host: %mailer_host% username: %mailer_user% password: %mailer_password% ‘parameters.yml’ like this mailer_transport: smtp mailer_encryption: ssl mailer_auth: login mailer_host: mailer_user: mailer_password: ****** Now I want to use more mail accounts to send mails for differ

Symfony SonataAdminBundle doesn't logout after accessing dashboard

Maybe this is a silly question and I just don't get it, but I'm trying to use Sonata and FOSUserBundle with a custom provider, I have my admin users in "myapp/backbundle/Entity/Administrador" everything works fine, I can access to my admin panel using http_basic login but when I want to logout my user and then I go back and access to www.mydomain/admin/ it seems like I never logged out. I just want my admin users (just me) to access admin zone that's why I want a simple validation login/logout,

Symfony override configuration from the app/config.yml

I have in my app/config.yml this: # Doctrine Configuration doctrine: dbal: driver: %database_driver% host: %database_host% port: %database_port% dbname: %database_name% user: %database_user% password: %database_password% orm: auto_generate_proxy_classes: %kernel.debug% auto_mapping: true Now I create my bundle and I want it to override some of this configuration: doctrine: orm: resolve_target

Custom entity provider in symfony: There is no user provider for user "...\...\Entity\User"

I have just implemented login functionality similar to this tutorial , but when I try to log in, I get: "There is no user provider for user "App\SomeBundle\Entity\User"" My repository implements required interface, user entity references to the repository and in security.yml I have defined provider like in example for custom entity provider. I'm lost why there is an error. In security.yml I have: security: encoders:

Symfony Sonata Media Bundle : How to set the default value of a media field?

I'm currently Sonata Media Bundle for my project. In one of my Entity Form Type that has some Media fields, I added these fields : <?php $builder ->add('image', 'sonata_media_type', array( 'provider' => '', 'context' => 'projects', 'label' => 'Project image', 'required' => true )) ->add('video', 'sonata_media_type', array( 'provider' => '', 'context' => '

How to access getDoctrine in call backs Symfony2

I've the following call back code in the admin class, <?php namespace IFI2\MainProjectBundle\Admin; use Sonata\AdminBundle\Admin\Admin; use Sonata\AdminBundle\Datagrid\DatagridMapper; use Sonata\AdminBundle\Datagrid\ListMapper; use Sonata\AdminBundle\Form\FormMapper; use Sonata\AdminBundle\Show\ShowMapper; class CobrandAdmin extends Admin { /** * @param DatagridMapper $datagridMapper */ protected function configureDatagridFilters(DatagridMapper $datagridMapper) {

Symfony Can I organize Doctrine entities or their mapping files into subfolders?

I have tried this directory structure for my mapping files: /config/doctrine/Place.orm.yml /config/doctrine/Place/Type.orm.yml /config/doctrine/Place/Price.orm.yml And have pointed to the corresponding Entity in my mapping file like this: Project\TestBundle\Entity\Place\Type: type: entity table: place_type id: id: type: integer generator: { strategy:AUTO } fields: name: type: string length: 255 But this returns an error. The system can't seem to dete

Symfony calling Medhod from a twig template and getting entityManager

I wanna add a button in the sonata admin list grid depending if the object satisfies a condition or not. I have a customize type template with this code : {% if object.myMedhod == true %} ///if response is true add a button in sonata admin list grid {% endif %} my entity extends a model class where I have myMedhod() my ModleClass: namespace myprject/myBundle/Model; use Doctrine\ORM\EntityManager; class XModel { private entityManager; public function __constuct(EntityManager $entityMa

Symfony assetic doesn't work properly

I have problem with assetic in symfony. Stylesheet part does not work at all in dev environment (css styles are not applied to the document) and in production environment everything is ok except resources are not linked correctly for fontawesome I am using bower and my .bowerrc file: { "directory": "src/Acme/AdminBundle/Resources/public/3rdparty" } My file: assetic: debug: "%kernel.debug%" use_controller: true bundles: ["AcmeAdminBundle"] filte

Symfony FOSUserBundle login form not showing after extending layout.html.twig

I've read the guide and after installing, configuring and overriding the default template I can browse to my Login page but only my header and footer show up, there is no login form. config.yml: fos_user: db_driver: orm firewall_name: main user_class: WX\ExchangeBundle\Entity\TblUser routing.yml: fos_user_security: resource: "@FOSUserBundle/Resources/config/routing/security.xml" fos_user_profile: resource: "@FOSUserBundle/Resources/config/routing/profile.xml" prefix

Symfony For loop - iterate from 1 to x

I have loop in Twig template: {% for item in 1..0 %} {{ item }} {% endfor %} (of course in real life instead of 0 there is variable value). I would expect in this example that loop won't be executed because 0 is lower than 1. But in fact it displays 1 0 Question: is there any way in this example using simple for loop in Twig (or other loop) to tell Twig I want to iterate ++ not -- or I have to add condition to check before loop if 0 is lower than 1 EDIT: Of course I'm aware I can c

symfony routing not take into account in app/config/routing

Here my main routing file (in app/confige/routing.yml), and the point is that whatever route I put, it works! I'm a bit lost! sdz_administration: resource: "@sdzAdministrationBundle/Resources/config/routing.yml" prefix: /{_locale}//whatever sdz_bikind: resource: "@sdzBikindBundle/Resources/config/routing.yml" prefix: /{_locale}//whatever requirements: _locale: en|fr|es sdz_user: resource: "@sdzUserBundle/Resources/config/routing.yml" prefix: / I hav

Symfony manyToOne is creating new products

I am trying to implement Sylius Cart Bundle, but every time I add a product to the cart, a new product is created. This is probably link to my line: cascade: ["persist", "remove"] In my YAML File: Pharmacie\FrontBundle\Entity\CartItem: type: entity table: app_cart_item manyToOne: produit: targetEntity: Pharmacie\FrontBundle\Entity\Product cascade: ["persist", "remove"] joinColumn: name: product_id referen

Symfony monolog after doctrine persist

I need to log all my users actions with monolog. But only if the actions persist data with doctrine, insert, update or delete. What should I do ? Could I define a generic method like "afterPersist" to log every action ? Thx ! EDIT : The Listener : use Doctrine\ODM\MongoDB\Event\OnFlushEventArgs; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Security\Core\SecurityContextInter

Symfony Select filtered collections of multiple entities using Doctrine join

I want to select two entities using doctrine join. $query = $em->createQuery("SELECT u, a FROM User u JOIN u.addresses a WHERE = 'Berlin'"); $users = $query->getResult(); I have followed the documentation here, the query work well but I didn't manage how to get the second entity. I tried this but it load the hole address array foreach($users as $user){ echo($user->getAddresses();//this contains all addresses not the filtered address } The documentation mentioned so

Symfony Many to Many, One to Many or Many to One

I am trying to get my head around Doctrine 2 ORM relationships, I thought I had the hang of it but after reading a few symfony cookbook entries, I suspect I am actually a little confused. I currently have a system where a template can contain multiple modules (including more than one of each type) and multiple templates can use the same module. I thought that this would warrant a ManyToMany relationship and indeed looking at my table, it seems to work quite well. However I realised as I was

symfony2 assetic source maps less

I'm using: - Symfony2 - Assetic(Bundle) - NodeJs tools for compiling css+js through assetic My less files are not stored in the public-dir (obviously). I want to use source mapping to be able to edit less/js files in the browser in a dev-environment. Looking at this question: Symfony2 Assetic and Less Sourcemaps I've already got mapping information at the bottom of each generated css file. But both Google Chrome and Mozilla Firefox fail to load the less files. Probably because they are not

Symfony2 SSL certificate, verify that the CA cert is OK. error:14090086

I got an error on my local test server: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed I'm using standard Symfony 2.5 + Payum payment bundle with paypal express checkout. Error comes when payum trying to do payment action. As i understand, payum using, to sent information, standard symfony http request api. And that api then looks like using Buzz Client(cURL) that located here: symfony\v

Symfony2 and Doctrine: The table with name '' already exists.

i working with Symfony2 and Doctrine ORM using MySql. When i try uo use: php app/console doctrine:migration:diff i have this error: [Doctrine\DBAL\Schema\SchemaException] The table with name '' already exists. My code in Post.php (i use annotation) is: namespace Blog\ModelBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /** * Post * * @ORM\Table() * @ORM\Entity */ class Post extends

Symfony Twig compare two values in different arrays

First of all I'm learning Twig. I was wondering if it is possible wit Twig to compare two different values from different arrays/lists?! I have two list of items I call them like so: {% if page.cart %} {% for product in page.cart.products %} {{ }} {% endfor %} {% endif %} And: {% if products %} {% for product in products %} {{ }} {% endfor %} {% endif %} I want to compare both's so I can create a new statement. Is there any way to compare both values?

Symfony jms serializer bundle serialize super class

I use jms serializer bundle to serialize a super class but i want to serialize my super class like this: /** * @Discriminator(field = "type", map = {"vehicle": "Vehicle", "car": "Car", "moped": "Moped"}) */ class Vehicle { } class Car extends Vehicle { } class Moped extends Vehicle { } but it doesn't work i can get fied 'type' in my json for children but not for my superclass Vehicle. For instant i use an hack: $data = $this->serializer->serialize($vehicle, 'json'); if(!strpos(",\"t

Symfony Which are limits of Community version of the eZ Publish CMS?

I am currently looking for informations about eZ Publish Community version and its limits to develop a public portal. Furthermore: Can I use Oracle database? Should I prefer ezoracle to any Symfony extension? Can I integrate an antivirus solution? If yes which one? Can I use 2 different instances, one to write and export contents, and another one to import and update contents? Which newsletter system do you suggest? Is back-end IE8 and IE9 compatible? Can I (de)activate contact forms on demand

Symfony SwiftMailer setBody with database

I have a problem to send a mail, since symfony 2.8 with SwiftMailer. Before, I used this method : $body = $this->twig->render($email->getCorp()); With an external service, but now I have this error : Unable to find template "<div>...template in database..." I've tried this too, and I've got the same error : $email = $em->getRepository('BoAdminBundle:Email')->find(3); $body = $this->render($email->getCorp()); $message = Swift_Message::newInstance()

Symfony dynamic function in twig template

I would like to display some dynamic text on many twig-templates. Instead of adding this variable to every Action , I would prefer to write it once and somehow add it to the templates like {{ displaytext('ann') }} How can I achieve this?

Symfony NotFoundHttpException with route :80

Using Symfony 3.1, I am having problem with NotFoundHttpException. facebook via requests route "GET :80/...", so I have added a specific route to redirect ":80" to the right route and it works when I request from the navigator (with and without a first slash), but I keep receiving errors and I don't know where to look (as log doesn't give any aditionnal data) and neither what to do. The full error message is request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKer

Symfony Iterate or count ArrayCollection from twig

symfony 2.8 Ok, I have a Category entity which looks like this: class Category { // ... // /** * @ORM\OneToMany(targetEntity="Classified", mappedBy="category") */ private $classified; // ... // public function __construct() { $this->classified = new ArrayCollection(); } } and the Classified entity looks like this: Class Classified { /** * @ORM\ManyToOne(targetEntity="Category", inversedBy="classified") */ private $categ

Symfony twig view checkbox value

I want to view a checkbox in a form. But it is displayed N/A for 0 and 1 for 1 . How do I format the checkbox value to No for 0 and Yes for 1? //twig <div class="responsive-block"> {{ UI.renderProperty('campuscrm.eventname.system_calendar.label'|trans, eventname.systemCalendar) }} </div> //FormType public function buildForm(FormBuilderInterface $builder, array $options) { // system calendar $builder->add( 'system_calendar', CheckboxType::class,

correct item choosed in twig for an edited form (symfony)

i want to edit an entity via a form : public function editerOffreAction($slug, Request $request) { $em = $this->getDoctrine()->getManager(); $offre = $em->getRepository('AppBundle:Offre')->findOneBySlug($slug); $form = $this->createForm(OffreType::class, $offre); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em->persist($offre); $em->flush(); return $this->redirectToRoute(

Symfony Wrong routing or wamp error ?

I just started a new symfony project, but I got something wrong with my wamp, and I don't know if this is coming from Wamp, vhost or Symfony. I hope you can help me. When I'm wanted to test my vhost, with the url kingdom/ I got this error 403: You don't have permission to access / on this server. Apache/2.4.23 (Win32) PHP/5.6.25 Server at kingdom Port 80 My contains # Virtual Hosts # <VirtualHost *:80> ServerName localhost ServerAlias localhost DocumentRoo

Symfony Doctrine onFlush - catch entity changed fields

I need to store all changed field in logs when user change something in Product Entity. I have event subscriber which works fine. I have two methods. Onflush and postFlush. In onFlush method I have simply this: public function onFlush(OnFlushEventArgs $args): void { $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); foreach ($uow->getScheduledEntityUpdates() as $key => $entity) { if ($entity instanceof Product) { $this->entitiesToProce

Symfony An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'db_user'@'localhost' (using password: YES)

I followed this documentation to add doctrine to my symfony project(v4.2). But when doctrine is installed it deosn't add this line to my project ( in my .env file like mentioned in the doc ): DATABASE_URL="mysql://db_user:db_password@" So I added it manually like this : DATABASE_URL="mysql://root@" and used this commande to create the database : php bin/console doctrine:database:create and it gives me this error : In AbstractMyS

Symfony i don't know what happened

I get: Error: Class App\Entity\User contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Symfony\Component\Security\Core\User\UserInterface::getUsername) use Symfony\Component\Security\Core\User\UserInterface; use App\Entity\Role; /** * @ORM\Entity(repositoryClass="App\Repository\UserRepository") */ class User implements UserInterface, \Serializable { /** * @ORM\Id() * @ORM\GeneratedV

Symfony Is it possible to create a group dependency in JMS

Lets say I have following structure: Article: name content galleries: array of Gallery Gallery: name description media : array of Media thumbnail: Media Media: name file Now when I am serializing The article or something that contains a gallery I need to specify groups for all children like this: 'groups' => [ 'All', 'gallery' => [ 'Details', 'thumbnail' => ['Basic'], ],

Symfony 5 project not installing with stof-doctrine-extensions

I try to create a new Symfony 5 project with doctrine extensions but it fails. Here is the sequence : $ symfony new myProject --full $ cd myProject $ composer require stof/doctrine-extensions-bundle ( as indicated in ) And it results in : Using version ^1.4 for stof/doctrine-extensions-bundle ./composer.json has been updated Loading composer repositories with package informati

Symfony ChoiceType with choices from a list of objects returns an object instead of string

Is there a specific option to force the ChoiceType field to return as a string? Well, actually, the submit does return a string, but somehow the handleRequest-function converts it back into an object , which it shouldn't! ("Expected string, got object" -error) To solve this quickly, I made a traditional list (key/label => value) looping through the objects and getting the label and value from each object, but that seems so unlike Symfony. This does not work with a countryList made o

Symfony 5 stripe v3 can't find CHECKOUT_SESSION_ID

I'm trying to handle monthly subscription with stripe : I create a Payment Controller with actions : create-checkout-session Action : /** * @Route ("/create-checkout-session", name="checkout") */ public function checkout(Request $request) { $data = json_decode($request->getContent()); \Stripe\Stripe::setApiKey('sk_test_...'); try { $checkout_session = \Stripe\Checkout\Session::create([ 'payment_method_

  1    2   3   4   5   6  ... 下一页 最后一页 共 94 页