symfony4
Using an environment variable (from `.env` file) in custom Twig function in Symfony 4
Here’s an easier way (Symfony 4) that does not involve any custom extensions. In my case, I wanted to set the Google Tag Manager Id as an environment variable in the .env file: GOOGLE_TAG_MANAGER_ID=”GTM-AAA12XX” Next, reference the environment variable in the config/packages/twig.yaml file: twig: globals: google_tag_manager_id: ‘%env(GOOGLE_TAG_MANAGER_ID)%’ Now you can use the tag manager value … Read more
How to add Fontawesome 5 to Symfony 4 using Webpack Encore
According font-awesome docs here, after install package yarn add –dev @fortawesome/fontawesome-free or npm install –save-dev @fortawesome/fontawesome-free Require font-awesome into your config file (in my case and default Symfony 4 location) assets/js/app.js: require(‘@fortawesome/fontawesome-free/css/all.min.css’); require(‘@fortawesome/fontawesome-free/js/all.js’); Compile again yarn encore dev and icons should appear.
Symfony 4: How to organize folder structure (namely, your business logic)
Conway’s law: organizations which design systems … are constrained to produce designs which are copies of the communication structures of these organizations. You should design your directory structure around how you organize work. If you or your colleagues work full-stack on per feature basis you should group your code per feature. It will make navigation … Read more
Symfony4 Expected String but got String
It is not an error of your code, it’s a error on your IDE, I assume that you are using PHPStorm, go to File > Invalidate Caches/ Restart .. that should solve it.
Symfony 4, get the root path of the project from a custom class (not a controller class)
In Symfony AppKernel class is handling the project root directory under method getProjectDir(). To get it in the controller you can do: $projectRoot = $this->get(‘kernel’)->getProjectDir(); it will return you a project root directory. If you need the project root directory in one of your classes you have two choices which I will present to you. … Read more
Cannot autowire service: Argument references class but no such service exists
Starting from the 1.8 version of DoctrineBundle, you can extend your class using Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository instead of Doctrine\ORM\EntityRepository. The result will be the same, but this does support the autowire. Example: use App\Entity\Activation; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Common\Persistence\ManagerRegistry; class ActivationRepository extends ServiceEntityRepository { public function __construct(ManagerRegistry $registry) { parent::__construct($registry, Activation::class); } // … }