Questions tagged [symfony]

26269 questions
1

votes
4

answer
760

Views

Symfony PHP Logout not working

I have a logout function that worked in another project but for some reason doesn't work in the project I am currently working on. It looks like it just refreshes the page. I checked the official documentation of Symfony https://symfony.com/doc/current/security.html but to no avail. Hope you guys ca...
Mr J.
1

votes
1

answer
63

Views

Symfony/Doctrine2 and Associative entity

Usually when querying in a custom repository class, I use something like this : SELECT * FROM BundleName:Entity But how do I do for associative entity ? I have an entity 'Ticket' and an entity 'Tag'. It's a ManyToMany relation. In phpMyAdmin, I've got a ticket_tag associative table but how do I get...
Thibaut Tang
1

votes
1

answer
601

Views

How validate data from post in restful api

I need to validate some data before insert into the database, for that i create a little service that return invalid fields from an entity. It works ok when validating single entities. class EntityValidator { protected $validator; public function __construct(ValidatorInterface $validator) { $this->v...
fajuchem
1

votes
1

answer
92

Views

Symfony 4 how to delete entity from OneToMany relationship

I'm having a bit of a problem deleting an entity assigned to another with a OneToMany relationship. I have an entity called Business and it has a property 'units' which is a collection of Unit entities on a OneToMany relationship (business can have many units). When i try to delete a single unit fro...
Glen Elkins
1

votes
2

answer
58

Views

How to set access_control to disallow users having a 'ROLE_USER' to access path: ^/login after successful login?

In security.yaml file we define the access control for various routes and the ROLES who can access that same route. But how can we set the user, who is logged-in but can't revisit the /login page unless and untill it logs out and 'ROLE_USER' changes to 'anon'. I am new to Symfony 4.2. Controller: na...
Saurabh
1

votes
1

answer
44

Views

How do I restrict an auto-generated route to accept only POST requests?

We have overridden Sonata's RegistrationController using Easy Extends. In our generated appDevProjectContainerUrlMatcher class, we now have the following lines: if ($pathinfo === '/password/reset') { return array ( '_controller' => 'Application\\Sonata\\UserBundle\\Controller\\RegistrationControll...
Patrick at work
1

votes
1

answer
42

Views

Symfony can't use mailer attachment AND filesystem

I want to send an email with a file attached to it, with swiftMailer, and after that, I want to delete the same file. But when I do it, it doesnt work. My file is not deleted, the mail is not sent, and there is a weird thing. Two emails are created. Here is the controller: public function rentIsPaid...
1

votes
1

answer
36

Views

Symfony 3 - How to recover and process an object in twig?

on my site it is possible to authenticate thanks to a CAS authentication. Then a search is performed in the database to retrieve the corresponding User object (with all of its attributes). This User object is then placed in the token. Arrived on the profile page of the user (twig), I wish I could at...
eronn
1

votes
2

answer
20

Views

ManyToMany new value must be an array or an instance of \Traversable, “NULL” given

I have a ManyToMany relation in my Symfony 4.2.6 application and I would like for it to be possible to have this to be null. So my first entity SpecialOffers is as follows : use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM;...
Dennis de Best
1

votes
0

answer
13

Views

Symfony 4 - Functional Test - Client not following redirects though followRedirects is true

I have been trying to start implementing some functionnal tests in the Symfony 4 application I am working on and I am failing to be redirected and eventually get a 200 response code from my index page even though I get a 200 response in the end when accessing it through the local symfony server. Her...
ZFL
1

votes
3

answer
9.9k

Views

Doctrine can't find the PostgreSQL PDO driver?

I see this question is very similar but I have PDO and pdo_pgsql installed Why does Doctrine say it can't find the PDO driver? Here is my error message: php app/console doctrine:mapping:convert yml ./src/Vendor/Bundle/MyBundle/Resources/config/doctrine/metadata/orm --from-database --force [PDOExcept...
Phill Pafford
0

votes
0

answer
4

Views

How to fix “touch(): Utime failed: Operation not permitted” on saving cache with symfony?

I want to caching some response with symfony\cache. But I've got some error with my cache and sometime with the symfony default cache. Configuration : Debian 9 on vagrant (with vagrant bindfs link to source code directory) with Apache2 php 7.2 / symfony 4.1 apcu enabled For caching my response I us...
SonOfWinter
1

votes
1

answer
221

Views

In Symfony2 what is the best way to use a multi word name and get a good RESTful url

I'm using the FOSRestBundle to build my symfony2 API. I have entities called things like SupportRequestTemplate, which I would like to see in the API end point but when I create the Actions with names like getSupportRequestTemplateAction(Request $request, $id) {} FOSRest treats each camel case word...
mike
0

votes
0

answer
4

Views

Using Symfony Validation component to validate specific array structure depending on key inside the given array

Given the following array: $a = [ ['type' => 'foo', 'abc' => 'whatever'], ['type' => 'bar', 'xyz' => 'whatever'], ]; I would like to use Symfony Validation component to validate $a. $a should be of type array, and each of the elements inside it should be arrays and should conform to one of two rules...
fearhr
1

votes
2

answer
426

Views

Symfony command runned by cron, but no effect. Runs fine on command line

I'm currently making a mail client with Symfony 2.7. I've made a command to collect new mails with IMAP and create entities from them. This command runs fine in command line, it collects and displays new mails. Here is the command : protected function configure() { parent::configure(); $this ->setN...
Blackwaxx
1

votes
2

answer
569

Views

Twig - Get corresponding alphabet letter in loop

I want to use the loop.index variable in twig to get the corresponding alphabet letter (1 = A, 2 = B, etc). {% for item in form.items %} {% set nom_item = 'Item'~loop.index %} {% endfor %} How could I do to get alphabet letter in loop ? I can't find a twig function for that.
1

votes
1

answer
997

Views

Symfony Serializer of DateTime Response String

When attempting to perform a doctrine query and serialze it to json (not using JSM, using the symfony serializer) I get the following in the json: ''due':{'timezone':{'name':'Europe/Berlin','transitions':[{'ts':-2147483648,'time':'1901-12-13T20:45:52+0000','offset':3208,'isdst':false,'abbr':'LMT'},{...
Lee
1

votes
2

answer
415

Views

Symfony 4 - controllers in two directories

In my application, I use Symfony 4. I want Symfony to search for controllers in two directories: A and B. I found something like this: controllers: resource: '../src/DirectoryA/Controller/' type: annotation , but it only works for one directory. How can I have Symfony to search for controllers i...
mariusz08
1

votes
1

answer
141

Views

Swagger Invalid json message received

I'm using Symphony 4 with Doctrine and now I'm implementing / adding Swagger, so I will have proper docs where testing my api will be available. This is my postman, with proper inputed form data and OK response. And this are my 'problematic' notations of Swagger * @Route( * '/request', * na...
Valor_
1

votes
2

answer
55

Views

how to properly transform date to string and back in symfony form so can use date picker

In my Symfony 4 app, I have an entity that includes a Date type field. By default, Symfony presents this as a set of select boxes for month, day, year. I've changed that to a text widget so that I can use a jQuery UI date picker. But I'm running into problems trying to submit the form. Here's the...
Erich
1

votes
2

answer
31

Views

Call Symfony Repository method with parameters from array

symfony 3.4 I have to call a function $this->em->getRepository($info['repoName'])->$info['funcName']->(//params the problem is that my function has parameters by coma like functionName($param1, $param2); and I receive an array that has values of this parameters in $arr['params'] VERY IMPORTANT! I w...
Testas Testauskas
1

votes
2

answer
36

Views

Bundle specific exception listener

Lets say I have 3 different bundles. I am adding to event listeners to each bundle. When there is any exception in Bundle1, then Bundle2 and Bundle3 should not listen it. I have tested it adding to each bundle eventlistener but when there is any error in Bundle2 then Bundle1 will listen try to handl...
MRustamzade
1

votes
1

answer
33

Views

Change symfony date type input display format

Hi I am using Symfony Date-Type with widget single_text. This is my code. use Symfony\Component\Form\Extension\Core\Type\DateType; // ... $builder->add('date_created', DateType::class, [ 'widget' => 'single_text', // this is actually the default format for single_text 'format' => 'yyyy-MM-dd', ]); A...
vimuth
1

votes
1

answer
51

Views

The class 'App\Form\Database_InteractionType' was not found in the chain configured namespaces App\Entity

Hello i can't find the error when i try to delete something out of my database. It says that my namespace is wrong but i really cant find any issues. Here is the action im calling /** * @Route('/delete/{id}', name='delete') * @param $id * @return \Symfony\Component\HttpFoundation\RedirectResponse *...
roibubble
1

votes
2

answer
2.9k

Views

How to make a macro in Twig?

I use a big piece of code for displaying friends and I use it in several templates, so I wanted to make it a macro, but the syntax is a way unusal and I don't know if there is a way this to be done. The part of the code, which I want to seperate is: {% if(fr.email != null) %} Email Address: {{ fr...
Faery
4

votes
4

answer
161

Views

DataTables API undefined with Symfony Webpack Encore

I'm using Webpack Encore with Symfony 3.4 (part of migration to Symfony 4). I have Datatables (installed via NPM to node_modules) working with jQuery but the api functions such as .columns are returning: .column is not a function at Package Versions: jQuery 2.14.4 Datatables 1.10.19 Webpack Encore 0...
Dan
1

votes
1

answer
459

Views

Symfony AbstractController Not Found After Composer Update

I just ran a composer update and now when I try to access my website I get this error: ClassNotFoundException in SecurityController.php line 28: Attempted to load class 'AbstractController' from namespace 'Symfony\Bundle\FrameworkBundle\Controller'. Did you forget a 'use' statement for another name...
LargeTuna
1

votes
1

answer
47

Views
1

votes
1

answer
43

Views

Execution of php file with commande

I use symfony 2.8 for my project. this is the code of php file that i would to execute with commande: use Video\IntelligenceBundle\Entity\Entry; use Video\IntelligenceBundle\Entity\Visits; use Doctrine\ORM\EntityManager; use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; use Symfony\C...
Melek
1

votes
0

answer
56

Views

Symfony does not read the base path propely after url rewrite

I've rewritten all urls from /api/(.*)$ to /api/public/index.php/$1 using this nginx configuration: location /api/ { try_files $uri @rewriteindex; } location @rewriteindex { rewrite ^/api/(.*)$ /api/public/index.php/$1 last; } location ~ ^/api/public/index\.php(/|$) { fastcgi_pass unix:/var/run/php-...
P. Danielski
1

votes
0

answer
52

Views

Unsupported index types through migrations. Schema:update wants to remove some

I have a symfony 3.4.2 + doctrine 2.6 project using postgresql 9.6. I am trying to add some unsupported index types. I found this issue which points out that migrations should be used for this purpose. My problem is that the migrations work for 2 out of 3 indices. But doctrine:schema:update wants 3r...
Evren Yurtesen
1

votes
0

answer
435

Views

Symfony/Process fails with exception

I'm trying to execute standalone chromedriver for linux with the Symfony/Process component. Here is the folder structure of the project: . ├── bin │   └── chromedriver-linux ├── composer.json ├── index.php └── vendor In index.php this is the code that I'm trying to...
lostbyte
1

votes
1

answer
129

Views

Is it possible in Twig to set autoescape strategy in the layout file

I have a layout file that has a {% block content %}{% endblock %} inside a Javascript array like this cols:[ {% block content %}{% endblock %} ]; And then is extended like this in the many templates that use the layout file like this (the real templates have many more lines of code and variables): {...
Technofrood
1

votes
0

answer
40

Views

Sonata E-commerce order bundle

I have just installed the sonata e-commerce OrderBundle, I want to add new field in order_order table without changing anything into the vendor. I have try it with add field into the Order entity, But it is not working. Please help. Thanks
Maulik Savaliya
1

votes
3

answer
720

Views

How to handle deadlock in Doctrine?

I have a mobile application and server based on Symfony which gives API for the mobile app. I have a situation, where users can like Post. When users like Post I add an entry in ManyToMany table that this particular user liked this particular Post (step 1). Then in Post table I increase likesCounter...
Tom
1

votes
1

answer
46

Views

Is it possible to combine fetch joins and COUNT in Doctrine?

I want to fetch join some entities to avoid a lot of additional queries and I also want to get count of related collection. Something like this: SELECT u, a, count(p) properties_count FROM User u JOIN u.address a LEFT JOIN u.properties p group by u.id That is I want to get a collection like [[0 =>...
AlexP11223
1

votes
0

answer
67

Views

Transform address string to (new) address entity before persisting data to database using a Symfony DataTransformer

I have a problem defining a special kind of form using Symfony2 3.3. General description of the problem: Storing postal address data in a flexible and clean way with reduced duplicates is a difficult task, because there are so many combinations of address components like street, streetnumber, zipcod...
A. Schmidt
1

votes
0

answer
181

Views

Use glob pattern to include controllers annotations routing with Symfony 4

I want to include all controllers for route annotation, giving a routes/annotations.yaml: controllers: resource: ../../src/{Site,Dashboard}/Controller/ type: annotation The glob component is not giving folders but null (whereas files exist). How can I use glob pattern in such way?
Thomas Decaux
1

votes
0

answer
103

Views

'Symfony3' - 'fosuserbundle' form - add group to user

I use Symfony 3 with the fosuserbundle, and want to create a form, that will add multiple groups to one user. The layout is not the problem, but to building the form and submitting... Here is the sourcecode with the important parts: https://pastebin.com/tyFP8XGK The current problem is that if I ha...
padhie
1

votes
1

answer
286

Views

SonataProductBundle (symfony 2.8) instead of showing product create form there is “No object types available” button appearing

There are Sonata Admin with enabled SonataProductBundle. Product entity configured accordingly to documentation. But, upon attempting to create new 'Product' in admin panel, 'No object types available' button appears instead of edit form of. Here are the configurations: config.yml imports: - { res...
Neha

View additional questions