creating pages in symfony 2 - template exception - symfony

I'm trying to run my first template in symfony 2 according to "Optional Step 3: Create the Template" from the book but I get an exception: Warning: filemtime() [<a href='function.filemtime'>function.filemtime</a>]: stat failed for C:\Server\Apache2\htdocs\SymfonyProject\src\Acme\HelloBundle/Resources/views/Default/index.html.twig in C:\Server\Apache2\htdocs\SymfonyProject\vendor\symfony\src\Symfony\Bundle\FrameworkBundle\Templating\Loader\FilesystemLoader.php line 68
Previous steps from the book work so I have no idea what is wrong.

If you delete an existing twig template, the framework will throw the error you've described. You need to clear your cache, even in the dev environment: php app/console cache:clear

Related

Symfony 6, Can't create a controller

I've installed Php 8 and I try to start coding with Symfony but I can't even create a controller.
I've created my project with:
create-project symfony/website-skeleton covid
The project was created with the version 6.1.99.
Then, in VScode, I used
symfony console make:controller Home
and it give me an error:
Parse error: syntax error, unexpected '?' in D:\Bureau\dev\covid\vendor\autoload_runtime.php on line 15
I don't understand why it's happening. Any idea ?
Edit:
It works fine if I use
php bin/console make:controller home
It seems I just can't use the symfony commands.

Autowiring does not work in Symfony 5.1 demo project with PHP 7.4.4

I am attempting to bootstrap a simple Symfony 5.1 project and I cannot get dependency injection / autowiring support to work. I am quite at the end of my abilities and need help. Here is what I do:
Create empty project by running: composer create-project symfony/website-skeleton testProject
Create files testProject/src/Util/Rot13Transformer.php and testProject/src/Service/TwitterClient.php with contents copy-pasted from this tutorial page: https://symfony.com/doc/current/service_container/autowiring.html
Check the services in console by executing
php bin/console debug:container App\Util\Rot13Transformer and php bin/console debug:container App\Service\TwitterClient
Output for both is:
------
Public no
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired yes
Autoconfigured yes
------
Open file testProject/public/index.php, add a new line after other use statements:
use App\Service\TwitterClient;
Add a new line just before kernel initialization at the end of the index file with following content:
$client = new TwitterClient();
Run this file on console with
php public/index.php
I always end up with error:
Too few arguments to function
App\Service\TwitterClient::__construct(), 0 passed in
/Users/oink/Documents/Development/testProject/public/index.php on line
27 and exactly 1 expected
Why? Should not autowiring take care of Rot13Transformer argument? Why does not it work? This is a vanilla example made on the basis of skeleton and with scripts copied/pasted from Symfony web site.
My PHP version is 7.4.4
Thanks!!

DependencyInjection Error - migration Symfony2 to Symfony3 - The argument "x" doesn't exist

I am performing migration from Symfony 2.7 to Symfony 3+. Multiple components and dependencies have been updated.
I managed to fix configurations issues regarding firewall setup, forms and some extenstions (services).
Sorting one problem introduced me to another.
Now each time I run php bin/console I get an error:
[Symfony\Component\DependencyInjection\Exception\OutOfBoundsException]
The argument "3" doesn't exist.
I have tried to run it with -v or -vvv option and I only got:
Exception trace:
() at /xx/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Definition.php:242
Symfony\Component\DependencyInjection\Definition->getArgument() at /xx/vendor/sonata-project/core-bundle/DependencyInjection/Compiler/FormFactoryCompilerPass.php:48
Sonata\CoreBundle\DependencyInjection\Compiler\FormFactoryCompilerPass->process() at /xx/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Compiler/Compiler.php:139
Symfony\Component\DependencyInjection\Compiler\Compiler->compile() at /xx/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/ContainerBuilder.php:710
Symfony\Component\DependencyInjection\ContainerBuilder->compile() at /xx/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:515
Symfony\Component\HttpKernel\Kernel->initializeContainer() at /xx/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php:117
Symfony\Component\HttpKernel\Kernel->boot() at /xx/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:68
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /xx/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
Symfony\Component\Console\Application->run() at /xx/bin/console:28
It looks like the issue with container compliation:
http://symfony.com/doc/current/components/dependency_injection/compilation.html
Some old setup passed validation but it is not consumed properly by DependencyInjection Compiler.
I have fallowing questions:
How I can debug it?
What can cause problem like this?
How to fix it?
Thanks!

Symfony2 doctrine:generate:entity and Fatal Parse Error

I'm getting started with Symfony2 and reading the book I got ot the doctrine entity generator code. Used the example in the book:
php app/console doctrine:generate:entity --no-interaction --entity="AppBundle:Category" --fields="name=string(255)"
and the new entity was created as expected, but I noticed that it generated some PHP code I'm not familiar with:
private $name=string(255);
and
public function setName=string(255)($name=string(255))
I've never seen before the string(255) when declaring a variable nor a function, and when I run
php app/console doctrine:generate:entities AppBundle
It throws an Fatal Parse Error on those lines. Removing the string(255) thing solves it. So, is it fine that Doctrine adds that code and my PHP interpreter's configuration is wrong? Doctrine shouldn't be adding that code or should I remove it after generating the entities? and finally, removing that code won't have consequences in the future?
Thanks,
If you look at the documentation for doctrine:generate:entity, you'll see that the format for declaring the fields looks actually like this:
... --fields="name:string(255)"
So you have to use a : (colon) to separate the field name of the type instead of an equal sign.

Symfony2 - Removed FOS User Bundle manually and now cannot clear cache in production mode

I installed FOS Userbundle to learn from it, but decided I didn't need it anymore. I then did the following to remove it. After removing, I ran composer update.
removed the bundle from the vendor folder
removed from the appKernel
removed from the composer.json file
removed the entity User.php file
removed the settings from config.yml, security.yml, routing.yml
Now when I attempt to clear cache for production mode I get the following error below. Clearing cache in dev mode works fine.
Can show me what I am doing wrong or what I am missing to remove FOS User Bundle and be able to clear cache in production mode?
PHP Fatal error: Class 'FOS\UserBundle\EventListener\LastLoginListener' not found in /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Component/EventDispatcher/ContainerAwareEventDispatcher.php on line 142
PHP Stack trace:
PHP 1. {main}() /var/www/html/HealthFitness/app/console:0
PHP 2. Symfony\Component\Console\Application->run() /var/www/html/HealthFitness/app/console:27
PHP 3. Symfony\Bundle\FrameworkBundle\Console\Application->doRun() /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php:121
PHP 4. Symfony\Component\DependencyInjection\Container->get() /var/www/html/HealthFitness/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:86
PHP 5. appProdProjectContainer->getEventDispatcherService() /var/www/html/HealthFitness/app/bootstrap.php.cache:2037
PHP 6. Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher->addSubscriberService() /var/www/html/HealthFitness/app/cache/prod/appProdProjectContainer.php:343
Your error indeed probably come from a cache error.
Have you this error executing php app/console cache:clear --env=prod ?
You can else delete app/cache/prod/* manually.
In case you can't remove the files manually this should work as well.
You could also use a --no-warmup and --no-optional-warmers switches:
cache:clear --no-warmup --no-optional-warmers --env=prod
that way it should not try to recreate the cache of non existing classes and then do a
cache:warmup --env=prod
Manually removing cache is faster though, but you still warm it up.

Resources