symfony4

How to pass an instance to symfony form validator class?

本小妞迷上赌 提交于 2019-12-31 02:54:11
问题 I am trying to create a custom symfony form validator constraint. I created two class, one constraint and one validator and it works fine. But I need to pass doctrine entitymanager instance to validator class, as I am using them standalone and not framework, I don't have yaml configuration file. I created a constructor in validator class to have $em, and in controller I have: ->add('email', EmailType::class, [ 'constraints' => [ new Assert\Email(['message' => 'invalid.email', 'mode' =>

Including Assets (CSS, JS) in Symfony 4 / Twig Template

丶灬走出姿态 提交于 2019-12-30 21:05:20
问题 Im learning Symfony and trying to set up a boilerplate app in Symfony 4 This Symfony document describes how to include assets in your page, namely using the asset package like so.. <img src="{{ asset('images/logo.png') }}" alt="Symfony!" /> <link href="{{ asset('css/blog.css') }}" rel="stylesheet" /> I have installed this package and trying to link to a css file in my /public directory. I know Symfony recommends placing assets in an /assets folder at the root, but I would like to avoid this

Symfony4 deploy to shared hosting

♀尐吖头ヾ 提交于 2019-12-30 07:50:09
问题 I'm using symfony4. Everything works in dev. But there is less tutorial for prod. How to deploy tutorial provides only less info (No info about shared hosting) Index.php prevents .env from reading the environment variables. Thats fine. But in Symfony2.x we can switch between env by app.php and app_dev.php front controllers. But in Symfony4 There is no such files only one index.php and an .env file According to the deploy link . How you set environment variables, depends on your setup: they

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

感情迁移 提交于 2019-12-30 06:22:35
问题 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;

live search in symfony4 using ajax+js

只愿长相守 提交于 2019-12-25 19:49:07
问题 i want to implement a live search under symfony 4 but im stuck. i hope your help friends. my controller /** * @Route("/search", name="search") */ public function searchAction(Request $request){ $user = new User(); $searchTerm = $request->query->get('search'); $em = $this->getDoctrine()->getManager(); $results = $em->getRepository(User::class)->findOneBy(['email' => $searchTerm]); //$results = $query->getResult(); $content = $this->renderView('search.html.twig', [ 'res' => $results, 'val' =>

doctrine/symfony 4 - avoid duplicate entry when persisting child entities

Deadly 提交于 2019-12-25 18:17:53
问题 I have the following setup: I parse an api response that has a structure similar to this (I oversimplify a bit): { orders: [ { // some data customers: [ { // some data addresses: [ { id: 436456445 // some data }, // Other addresses ] } ] }, { customers: [ { addresses: [ { id: 436456445 // some data } ] } ] } ] } Note that a specific address appears twice in the response (same id). I deep travel (hope is the right translation) the structure and make entities. All goes well until the save part

Symfony 4: Cannot access admin roles. Access Denied

时光毁灭记忆、已成空白 提交于 2019-12-25 02:47:30
问题 I'm learning Symfony 4 and try to make follow Symfony 4 Documentation to create an app. I do follow this article to make admin roles. But when I access path /admin , it's always "Access Denied." I read many article in Symfony Documentation page and StackOverflow but can not found the way to solve it. Here is my setting //config/packges/security.yaml security: encoders: App\Entity\User: algorithm: bcrypt providers: our_db_provider: entity: class: App\Entity\User in_memory: memory: users: admin

How symfony parse and use annotation

白昼怎懂夜的黑 提交于 2019-12-25 02:20:44
问题 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. 回答1: 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

Submiting data in a ManyToMany relation

陌路散爱 提交于 2019-12-25 00:40:49
问题 I have 2 entities, Parking and Agent, each parking can have many Agents and each Agent can administer many parkings. After I created the relationship, Doctrine automatically added a join table called parking-Agent. Now I'm trying to populate that table through a form, like when creating a new Agent I can give him one or many parkings, or Vice-Versa. I tried adding a choicetype with multiple choices to the form but it didn't work. Can you guys help me ? Entity Agent: <?php /** * @ORM\Entity *

How to find out what values are good for memory_cost, threads and time_cost for Argon2i in Symfony 4?

ぐ巨炮叔叔 提交于 2019-12-24 20:48:37
问题 I want to use Argon2i for my Symfony 4 encoder as I've seen multiple articles about how it's supposedly better than bcrypt or pbkdf2. Unfortunately I don't really know what values to use for the memory_cost, time_cost or threads on my system. What are good values and how can I figure out what my values should be? 回答1: What are good values? This is HIGHLY subjective based on your server. @Martin has done a reasonbly good description of this here and you can read the RFC specs here. But to