symfony4

Symfony 4 : ignore kernel events coming from debug toolbar

廉价感情. 提交于 2019-12-01 09:12:27
问题 I'm quite new to Symfony so forgive me if it seems obvious for you :) For my project, i need to perform some actions depending on the url. I use kernel events, more specifically the kernel request to do so. In services.yaml : App\Service\UrlManager: tags: - { name: kernel.event_listener, event: kernel.request} In UrlManager.php : public function onKernelRequest(GetResponseEvent $event) { $request = Request::createFromGlobals(); $hostname = parse_url($request->server->get('HTTP_HOST'),PHP_URL

API-Platform JWT : No route found for “GET /api/login”

笑着哭i 提交于 2019-12-01 07:55:55
问题 I successfully installed API Platform, it works well with all my entities. Now i'm trying to add JWT authentication whith LexikJWTAuthenticationBundle, but when i send the request for login i get : No route found for "GET /api/login" My request : http://localhost:8000/api/login?username=john&password=doe I'm using Symfony 4, here is my security.yaml : encoders: App\Entity\User: algorithm: bcrypt providers: entity_provider: entity: class: App\Entity\User property: username firewalls: login:

symfony 4 webpack + encore handle image in template more info

南楼画角 提交于 2019-12-01 06:23:49
问题 Like this question: Using Symfony 4 with Webpack + Encore + Yarn, I want to handle images in my templates, and I am not really how to achieve this. I put my image in my /assets/img/logo.png folder, and use this in my webpack.config.js: .addEntry('logo', './assets/img/logo.png') And after I run : yarn run encore dev Which generates /public/build/logo.js and /public/build/images/logo.aez323a.png files. I would like to know: What is the "logo.js" for? And how can I keep my directory structure.

How can I retrieve my environment variables in a parameter file in Symfony4 structure?

≯℡__Kan透↙ 提交于 2019-12-01 03:26:01
I did a fresh Symfony installation by using Symfony Flex and the new skeleton belong to the next Symfony 4 directory structure. I add and configure a first third-party bundle : HWIOAuthBundle . This bundle is used to connect via Twitter using two secret information. I declare my consumer_id and my consumer_secret in the config/packages/hwi_oauth.yaml file. hwi_oauth: firewall_names: [secured_area] resource_owners: twitter: type: twitter client_id: XXXXXMyIdXXXXX client_secret: XXXXXMyTopSecretKeyXXXXX My application works fine. But I cannot commit my secrets on github! I want to have a hwi

Symfony 4 serialize entity wihout relations

自闭症网瘾萝莉.ら 提交于 2019-11-30 22:09:25
I've have to log changes of each entities. I've Listener which listen for doctrine's events on preRemove, postUpdate and postDelete. My enity AccessModule has relations: App\Entity\AccessModule.php /** * @ORM\OneToMany(targetEntity="App\Entity\AccessModule", mappedBy="parent") * @ORM\OrderBy({"id" = "ASC"}) */ private $children; /** * @ORM\ManyToOne(targetEntity="App\Entity\AccessModule", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true) */ private $parent; /** * @ORM\ManyToMany(targetEntity="App\Entity\AccessModuleRoute", inversedBy="access

Symfony 4 SwiftMailer Gmail : Email not sent

陌路散爱 提交于 2019-11-30 21:07:57
I'm currently working on a Symfony 4 application and I need to send emails throught Swift Mailer. When I send an email, I receive the email spooled but I don't get it in my Gmail Mailbox. I allowed unsecure apps in my gmail configuration. This is my mailer URL from .env file : MAILER_URL=gmail://ep****@gmail.com:PASSWORD@localhost This is my swiftmailer.yaml: #config/packages/swiftmailer.yaml swiftmailer: url: '%env(MAILER_URL)%' spool: { type: 'memory' } This is my controller function: src/Controller/AccountController.php This is the documentation I've followed : http://symfony.com/doc

Symfony Error: “An exception has been thrown during the rendering of a template”

大憨熊 提交于 2019-11-30 19:14:13
I am trying to include <link href="{{ asset('css/mystyle.css') }}" rel="stylesheet"/> in my twig file and render it. But it gives me Uncaught PHP Exception Twig_Error_Runtime: "An exception has been thrown during the rendering of a template ("Asset manifest file "/../public/build/manifest.json" does not exist.") It does work when i use link href="css/mystyle.css" rel="stylesheet"/> . Following is my controller: <?php namespace App\Controller; use Symfony\Component\Routing\Annotation\Route; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation

Symfony 4 serialize entity wihout relations

狂风中的少年 提交于 2019-11-30 05:34:25
问题 I've have to log changes of each entities. I've Listener which listen for doctrine's events on preRemove, postUpdate and postDelete. My enity AccessModule has relations: App\Entity\AccessModule.php /** * @ORM\OneToMany(targetEntity="App\Entity\AccessModule", mappedBy="parent") * @ORM\OrderBy({"id" = "ASC"}) */ private $children; /** * @ORM\ManyToOne(targetEntity="App\Entity\AccessModule", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", nullable=true) */

Symfony 4 global route prefix

拜拜、爱过 提交于 2019-11-29 12:29:51
I can't find any info about the global route prefix in a Symfony 4 application. The only thing I've found is annotating the controllers with @route . But I don't use annotations and I need all the controllers to have the same prefix. Now I could do that in S3 like this in the app/config/routing.yml file: app: resource: '@AppBundle/Controller/' type: annotation prefix: /foo But S4 is bundleless and I can't do the same - I would have to create a bundle which I don't need. Is it possible to define a global route prefix in Symfony 4 at all or I'm going to end up with prefixing every single root

Symfony 4: How to organize folder structure (namely, your business logic)

ぐ巨炮叔叔 提交于 2019-11-28 16:14:18
In the Symfony Best Practices is advised to not use bundles to organize business logic. The bundles should be used only when the code in them is meant to be reused as-is in other applications: But a bundle is meant to be something that can be reused as a stand-alone piece of software. If UserBundle cannot be used "as is" in other Symfony apps, then it shouldn't be its own bundle. So, as I'm upgrading my app from Symfony 3.3 to Symfony 4, I think this is the right time to reorganize my code. At the moment I have followed the "bundled-structure": - src - AppBundle - Controller - Entity -