symfony4

Symfony 4: Test DB for JWT and Behat

邮差的信 提交于 2019-12-04 11:18:41
I am using API Platform 2.1 with Symfony 4 and I am using the LexikJWTAuthenticationBundle for authentication, and Behat for testing. I am unable to set things up properly. Here is my configuration so far: Feature: Books feature @createSchema @dropSchema Scenario: Adding a new book When I add "Content-Type" header equal to "application/json" And I add "Accept" header equal to "application/json" And I send a "POST" request to "/api/books" with body: """ { "title": "King", "author": "T. M. Frazier", "enabled": true } """ Then the response status code should be 201 And the response should be in

Symfony 4. InheritanceType(“JOINED”) and ParamConverter. Strange phenomenon

我与影子孤独终老i 提交于 2019-12-04 05:36:29
问题 I have defined the class CoreCase /** * @ORM\Entity(repositoryClass="App\Repository\CoreCaseRepository") * @ORM\InheritanceType("JOINED") * @ORM\DiscriminatorColumn(name="type", type="string") * @ORM\DiscriminatorMap({"Diesel" = "DieselCase", "Carloan" = "CarloanCase"}) * @ORM\HasLifecycleCallbacks() * */ abstract class CoreCase { . . . } and two classes DieselCase and Carloan: /** * @ORM\Entity * @ORM\HasLifecycleCallbacks() */ class DieselCase extends CoreCase { . . . } /** * @ORM\Entity

Ajax is losing sessions

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:31:33
问题 I upgraded my Symfony application from Symfony 4.0.7 to Symfony 4.1 and after that AJAX calls are losing sessions values. I have about 6 ajax requests called at the same time. First of them is going fine but others are losing session values. It happened only after migration to Symfony 4.1 and only for AJAX calls. Any ideas? edit: It happens only with ajax called at the same time. WHen I add eg 100 miliseconds delay between calling ajax then all works fine. edit2: it happens on 4 different

Symfony 4, How to implement a general controller as a service?

风格不统一 提交于 2019-12-04 01:58:20
问题 I have this controller Controller1.php <?php namespace App\Controller; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; class file1Controller extends AbstractController { /** * @Route("/Some/URI", methods={"GET"}) * @param Request $request * @return JsonResponse */ public function list(Request $request) { if (empty($request->headers-

Symfony4 Error loading classes custom folder “Expected to find class… but it was not found”

让人想犯罪 __ 提交于 2019-12-04 01:47:49
Problem I'm trying to setup a custom directory structure for some shared classes in my Symfony project. I want to create a custom folder in the root of my project and I want to use the Symfony auto-load feature to automatically register services from that folder. So I added a custom services namespace to the services.yaml file: # src ./config/services.yaml services: ... TestNamespace\: resource: '../TestNamespace/*' ... And I added an empty class in the custom folder: # src ./TestNamespace/TestClass.php namespace TestNamespace; class TestClass { } When I run the app I get the following error:

symfony 4 : How to get “/public” from RootDir

不羁岁月 提交于 2019-12-04 01:24:48
I have an image under the public folder. How can I get my image directory in symfony4 ? In symfony 3, it's equivalent is : $webPath = $this->get('kernel')->getRootDir() . '/../web/'; You can use either $webPath = $this->get('kernel')->getProjectDir() . '/public/'; Or the parameter %kernel.project_dir% $container->getParameter('kernel.project_dir') . '/public/'; It is a bad practice to inject the whole container , just to access parameters, if you are not in a controller. Just auto wire the ParameterBagInterface like this, protected $parameterBag; public function __construct

Symfony 4 login form with security and database users

烂漫一生 提交于 2019-12-03 20:28:12
I was a total noob on Symfony about a week ago and I thought I should just dive in Symfony 4. After a week of trying to solve the basic login problem, I believe the documentation is still missing some parts. Now I've found a solution and I will share it along with some tips on what you might be doing wrong. First part of the answer is a list of suggestions, while the second part is the creation of a project with working login from scratch (supposing you already have composer installed and using a server like apache). Part 1: Suggestions 403 Forbidden Check the access_control: key in security

Symfony 4, get the root path of the project from a custom class (not a controller class)

坚强是说给别人听的谎言 提交于 2019-12-03 16:36:20
In the src/Utils directory, I created a custom class Foo for various things. I'm looking for a way to get the absolute root path of the symfony 4 project From a controller, its easy with : $webPath = $this->get('kernel')->getProjectDir(); But from a custom class I created in my src/Utils directory, how can I get the root path directory ? I could pass the path from the controller to the Foo class : $webPath = $this->get('kernel')->getProjectDir(); $faa = new Foo($webPath); $faa->doSomething(); but I think its more proper to store this information in the Foo class and have only "controller logic

How to load, process and use custom parameters from Yaml configuration files in DI Extension class?

你离开我真会死。 提交于 2019-12-03 07:48:53
I'm trying to import a yaml configuration file in my App following the documentation provided here http://symfony.com/doc/current/bundles/extension.html but I always have the error message: There is no extension able to load the configuration for "app" My file is located here : config/packages/app.yaml and has the following structure : app: list: model1: prop1: value1 prop2: value2 model2: ... As this is a simple App, all the files are in src/ . So I have src/DependencyInjection/AppExtension.php <?php namespace App\DependencyInjection; use Symfony\Component\DependencyInjection\ContainerBuilder

How symfony parse and use annotation

混江龙づ霸主 提交于 2019-12-02 10:19:26
Using Symfony annotation for example for routing is quite amazing, but I wonder how this framework parse the comments and extract the annotation? For example: /** * @Route("/tehran", name="tehran") */ and then use it as a route to next controller method. Symfony uses the Doctrine Annotations module to parse the docblock from your class. See: https://github.com/doctrine/annotations https://doctrine-common.readthedocs.io/en/latest/reference/annotations.html It uses Reflection class to read the annotations https://secure.php.net/manual/fr/book.reflection.php Symfony will read from your