Category : symfony5

In a Symfony 5.3 Application I want to implement a simple password change form. In the controller method managing the process I inject UserPasswordHasherInterface and get the password from the form. Something like this: public function userChangePassword( Request $request, UserPasswordHasherInterface $passwordHasher ): Response { $user = $this->getUser(); $userChangePasswordForm = $this->createForm( UserChangePasswordType::class, $user ); $userChangePasswordForm->handleRequest( $request ..

Read more

I’m trying to create a reusable bundle and i get Invalid type for path "bayard_directus.authentication.email". Expected "array", but got "string" the TreeBuilder looks like this: $treeBuilder = new TreeBuilder(‘bayard_directus’); $treeBuilder->getRootNode() ->children() ->arrayNode(‘authentication’) ->arrayPrototype() ->children() ->scalarNode(’email’)->defaultValue("%env(PEE_CMS_API_MAIL)%")->end() ->scalarNode(‘password’)->defaultValue("%env(PEE_CMS_API_PWD)%")->end() ->scalarNode(‘cache’)->defaultValue(‘PSR-6’)->end() ->end() ->end() ->end() ->scalarNode(‘base_url’)->defaultValue("%env(PEE_CMS_API_URL)%")->end() ->end() ->end() ; return $treeBuilder; the YML file : bayard_directus: authentication: email: ‘%env(PEE_CMS_API_MAIL)%’ password: ..

Read more

With Symfony 5.1 and PHP 7.4, I want to add preload.php in opcache. Symfony documentation : During container compilation (e.g. when running the cache:clear command), Symfony generates a file called preload.php in the config/ directory with the list of classes to preload. opcache.preload=/path/to/project/config/preload.php But when I execute cache:clear, I don’t have preload.php file in /config/ ..

Read more

Symfony: change database dynamically I have similar situation – I need to perform a quick lookup and set the host or database on the fly, based on URI patterns. I have tried getting this to work – but I am not understanding something: <?php namespace AppDecorator; use DoctrineDBALConnection; class DynamicConnection extends Connection { public function ..

Read more

I am attempting to upload a file via an API endpoint controller I have created: /** * @Route("/upload", methods="POST") */ public function upload(Request $request) { $form = $this->createForm(UserFileType::class); $form->handleRequest($request); if (!$form->isSubmitted()) { dd($request->files->get(‘file’)); } … The dd($request->files->get(‘file’)) is showing my file as expected so I am unclear why isSubmitted() is returning false when the method ..

Read more

I have a simple contact form. Within the form I would like to change the color of the help text In FormType I added i. e. the name field: $builder ->add(‘name’, TextType::class, [‘help’ => ‘Pflichtfeld’]) In Twig I have this: <div class="row"> <div class="col"> {{ form_label(ContactForm.name)}} {{ form_widget(ContactForm.name) }} {{ form_help(ContactForm.name, {‘help_attr’: {‘class’:’text-danger’}}) }} </div> ..

Read more