symfony4

How to inject global variables into all templates?

≡放荡痞女 提交于 2021-01-28 04:58:53
问题 In my twig template there are some variables that are required on each page like userName , userId or userImage . What is the best way to inject them into the template? I already read the article How to Inject Variables into all Templates but how could I write a variable (e.g. current user) into the config/packages/twig.php file? Right now there is code like this in every controller: return $this->render('admin/users/index.html.twig', [ "allUsers" => $allUsers, "pageTitle" =>

How to inject Doctrine Entity Manager into Symfony 4 Service

泄露秘密 提交于 2021-01-27 05:15:07
问题 I have a controller use Doctrine\ORM\EntityManagerInterface: class ExampleController{ public function someFunction(ExampleService $injectedService){ $injectedService->serviceFunction(); } } With a Service use Doctrine\ORM\EntityManagerInterface; class ExampleService{ public function __construct(EntityManagerInterface $em){ ... } } However, calls to someFunction() fail due to 0 parameters being passed (the EntityManagerInterface is not being injected). I am attempting to use the EntityManager

How to inject Doctrine Entity Manager into Symfony 4 Service

时光总嘲笑我的痴心妄想 提交于 2021-01-27 05:15:07
问题 I have a controller use Doctrine\ORM\EntityManagerInterface: class ExampleController{ public function someFunction(ExampleService $injectedService){ $injectedService->serviceFunction(); } } With a Service use Doctrine\ORM\EntityManagerInterface; class ExampleService{ public function __construct(EntityManagerInterface $em){ ... } } However, calls to someFunction() fail due to 0 parameters being passed (the EntityManagerInterface is not being injected). I am attempting to use the EntityManager

Symfony4 “object not found by the @ParamConverter annotation” 404 error

别来无恙 提交于 2021-01-27 04:07:56
问题 I discover Symfony4 with similar blog sample like describe in https://symfony.com/doc/current/routing.html Then I added a new route to add /blog/about page. So a part of code in my src/Controller/BlogController.php is: /** * @Route("/blog/{id}", name="blog_show") */ public function show(Description $article) { return $this->render('blog/show.html.twig', [ 'article' => $article, ]); } /** * @Route("blog/about", name="about") */ public function about() { return $this->render('blog/about.html

Symfony4 “object not found by the @ParamConverter annotation” 404 error

谁都会走 提交于 2021-01-27 04:07:40
问题 I discover Symfony4 with similar blog sample like describe in https://symfony.com/doc/current/routing.html Then I added a new route to add /blog/about page. So a part of code in my src/Controller/BlogController.php is: /** * @Route("/blog/{id}", name="blog_show") */ public function show(Description $article) { return $this->render('blog/show.html.twig', [ 'article' => $article, ]); } /** * @Route("blog/about", name="about") */ public function about() { return $this->render('blog/about.html

VichUploaderBundle - PropertyAccessor requires a graph of objects or arrays to operate on, but it found type “NULL”

流过昼夜 提交于 2021-01-05 07:49:05
问题 i try to make this bundle running with Form. First this is my entity <?php namespace App\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\File\UploadedFile; use Vich\UploaderBundle\Entity\File as EmbeddedFile; use Vich\UploaderBundle\Mapping\Annotation as Vich; /** * @ORM\Entity(repositoryClass="App\Repository\BanqueRepository") * @Vich\Uploadable */ class Banque { /** * @ORM\Id() * @ORM\GeneratedValue() * @ORM

Attempted to load class “WebProfilerBundle” from namespace “Symfony\Bundle\WebProfilerBundle” when deploying on Heroku using development dependencies

旧街凉风 提交于 2020-12-31 07:38:22
问题 We have a Symfony 4.3 web application hosted on Heroku. This is a new setup and we never managed to have the dev mode to work correctly . There are plenty of similar issues online but none fixes the exact symptoms we are facing here. The project was created with a command line: composer create-project symfony/website-skeleton appName Let me clarify that: we do not want to change from "dev" to "prod" We need to be able to use the application in dev mode in order to take advantage of error

Symfony 4 extremely slow on windows

爷,独闯天下 提交于 2020-12-29 03:22:51
问题 I've used Symfony on Windows 10 for my projects for a few years (SF2, SF3), and I recently moved to Symfony 4 to build a new project but performances are catastrophic. Symfony initialization time takes from 5 to 25s, as in this example It is the same with console: for example a cache:clear can last 1 minute. I searched for similar problems and issues in Symfony doc and forums, and I've tested recommended optimizations (increase some values for ​​opcache , enable APCu , disable xdebug , add

Symfony 4 extremely slow on windows

别说谁变了你拦得住时间么 提交于 2020-12-29 03:20:14
问题 I've used Symfony on Windows 10 for my projects for a few years (SF2, SF3), and I recently moved to Symfony 4 to build a new project but performances are catastrophic. Symfony initialization time takes from 5 to 25s, as in this example It is the same with console: for example a cache:clear can last 1 minute. I searched for similar problems and issues in Symfony doc and forums, and I've tested recommended optimizations (increase some values for ​​opcache , enable APCu , disable xdebug , add

Symfony 4 extremely slow on windows

蓝咒 提交于 2020-12-29 03:20:06
问题 I've used Symfony on Windows 10 for my projects for a few years (SF2, SF3), and I recently moved to Symfony 4 to build a new project but performances are catastrophic. Symfony initialization time takes from 5 to 25s, as in this example It is the same with console: for example a cache:clear can last 1 minute. I searched for similar problems and issues in Symfony doc and forums, and I've tested recommended optimizations (increase some values for ​​opcache , enable APCu , disable xdebug , add