help please, i have this error: Attempted to load class "User" from namespace "UserBundle\Entity". Did you forget a "use" statement for e.g. "Symfony\Component\Security\Core\User\User", "Symfony\Bridge\Doctrine\Tests\Fixtures\User", "FOS\UserBundle\Model\User", "FOS\RestBundle\Tests\Fixtures\User" or "AppBundle\Entity\User"?
Look's like you just forgot to import that class. Check at the top of your file in the imports section, if you cannot see it in there, then just add it :)
Hi, my project doesn't have the app folder, because probably in the creation I have build a Symfony Skeleton and not a normal one. How can I do this steps with my project? I have tried to check for appkernel in the folder but the source code looks completly differente compareted to yours. SOLVED After doing php bin/console he said to me: In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:
The service "fos_user.resetting.controller" has a dependency on a non-existent service "templating". SOLVED When I do: php bin/console doctrine:migrations:diff
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002] The connection could not be verified. Persistent computer rejection by DESTINATION.
my project doesn't have the app folder... That's because (I believe) you are on Symfony4 and this course is on Symfony3, the architecture changed considerably from S3 to S4. You can watch our tutorial about upgrading to Symfony4 if you are interested in learning more about those changes.
About your DB problem "Persistent computer rejection by DESTINATION" - Wow, that's an interesting error. What's your DB system, MySQL? Verify your DB connection, in Symfony4 you should define your connection string in an environment variable named "DATABASE_URL". Something like this
So I have configured the .env putting a password and a server name, but when I try to create a server using php bin/console doctrine:database:create It prints me the same error as written before: "Persistent computer rejection by DESTINATION"
Do I have to set a local db using MySql? I have never used before MySql, so I would like to know if it's possibile to use PostgreSql with Symfony/Docrine.
Ohh, so you are using a third party for your Database, like RDS from Amazon? If that's the case, you can use it, you only have to tweak the connection string
> Do I have to set a local db using MySql? I have never used before MySql, so I would like to know if it's possibile to use PostgreSql with Symfony/Docrine.
Symfony doesn't care about which DB engine you use, but Doctrine does. I'm not sure if Doctrine supports Postgres but you may want to do a quick search about it. Anyway, using MySql is pretty easy, so you may want to give it a try ;) (And, yes, you would have to set up a local MySql server)
done smooth no problem and error :) i wanna ask question can i alter router annotation when the user done register? or like i wanna change the router from localhost/register into bookstore/register
Let me know if that helps! If you want to redirect to a different URL after a successful registration, the best way to do that is to listen to the REGISTRATION_COMPLETED event. You will be passed a FilterUserResponseEvent object, and you can create a new RedirectResponse to a different url and call $event->setResponse() to set your new Response on that object.
Running Symfony 4.1 and found the doctrine:migrations:generate and diff commands just created migrations with VOID inside (ie there was no SQL), so then running migrate would create/update the migration version table but not create the users table. However running doctrine:schema:update --force and it worked!!! Is this a Symfony 4 thing, or could I have done something wrong?
Hmm, that is super strange! Well, sort of strange :). The doctrine:migrations:generate always creates empty migrations. But, the doctrine:migrations:diff command "should" (with quotes... because sometimes surprises happen in tech!) behave the exact same way as doctrine:schema:update. In fact, they use the same code behind the scenes to determine what queries to generate.
So, question time :).
1) Are you sure you tried running doctrine:migrations:diff? 2) Can you still repeat this? Like, if you drop your database and run doctrine:migrations:diff, is it still empty?
There's nothing special related to Symfony 4 for all of this. It's *possible* there's some misconfiguration... but I really can't imagine what it is!
Can you tell me please the plugins for the sublime text you are using? The new file plugins which let you add different types of files with the right button. Thank you.
For this course (and actually for every course) Ryan uses PhpStorm as his text editor. I'm not sure if there exists the same plugins for Sublime as in PhpStorm, but maybe they do?
Following along with the new fosuserbundle tutorial. The command .'/bin/console doctrine:migrations:diff' throws a command not found exception. The note says to install the DoctrineMigrationsBundle. Following this link the said mentioned command is again listed and results in the same error. Help I'm stuck in an endless loop LOL.
You're right, the command is valid. But did you install the DoctrineMigrationsBundle properly? :) There're a few steps you need to do to install it by following that link: 1. Require this bundle with "$ composer require doctrine/doctrine-migrations-bundle" 2. Add "new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()," line to the app/Kernel.php file to register the bundle.
And then "./bin/console doctrine:migrations:diff" should work well.
Unfortunately, we do not have exactly this screencast, but I have a few link where you can find useful for you information: - https://knpuniversity.com/s... - here's how you can send forms via AJAX. - https://knpuniversity.com/s... - here's how you can handle an AJAX response.
So along the next screencast https://knpuniversity.com/s... you can create and render your login/register forms, but then intercept their sending with JS and send data with AJAX to the controller where you handle the request and return a JSON response for example which will say was the login/register successful or form has some errors. You can also do it along FOSUserBundle https://knpuniversity.com/s... , but probably you'll need to customize some third-party code by overriding it because FOSUserBundle does not work via AJAX out-of-the-box, so it could be more complex because you'll need to customize their actions, or write completely new ones.
Of course is possible, but I would recommend you to use "yaml" instead of "xml", well, because, no body enjoys reading xml If you have "auto_mapping" enabled (this is a default), then you just have to store your files inside "Resources/config/doctrine" (in your bundle) and Symfony will find them, but do not try to use more than one type of mapping, because Symfony reads only one type of mapping.
I'm getting an error when trying to register a user. It looks like the password fiedls aren't getting registered:
An exception occurred while executing 'INSERT INTO `user` (username, username_canonical, email, email_canonical, enabled, salt, password, last_login, confirmation_token, password_requested_at, roles) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["aquanaut1", "aquanaut1", "aquanaut1@gmail.com", "aquanaut1@gmail.com", 1, null, null, null, null, null, "a:0:{}"]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'password' cannot be null```
I noticed in composer.json that the user bundle wasn't registered, but after running the install command again I got green lights in the console and it was in the required section of composer.json.
Google's not being too helpful. Has anyone else seen this error?
Update: I'm getting the same with the finish folder in the sample code.
I'm assuming it's something to do with php7.1/zendserver but I can't test anywhere else at the moment :(
Hm, most likely this error is due to unfired event listener from FOSUserBundle which encodes plain password and sets the encoded password with User::setPassword() (IIRC the password is encoded and set in event listener in FOSUserBundle). Do you get this error in the prod environment? Because to update configuration you need to clear the prod cache after you install and configure the FOSUserBundle. You said you had got the same error with our downloaded Course Code. Did you update our code from the finish/ directory to Symfony 3.3 ? Because I can't reproduce it by myself: I downloaded the Course Code, went to the finish/ dir, installed composer dependencies, created DB, ran migrations, loaded fixtures, ran the Symfony web server, then went to /register page in dev environment and registered new user without any errors. Im I missing some steps? And one more question, what PHP version do you use? I tested it on PHP 7.1.5.
Those are the exact steps I took with the finish folder. Just installed, not updated (Although I did try updating later on but the error wwas the same). I'm running php 7.1.3, same error in prod Just about to try the same steps with a blank symfony project and see if that's the same. I had no issues with the security chapter of the symfony 3 course.
Let us know what you find out! It's weird because - if the bundle is not installed in composer or in AppKernel, then you won't even be able to get to /register at all. The fact that you could get there... but it failed on submit... that's the strange part ;).
Hi Ryan, I did install the FOSUserBundle and go through all the steps, it just errored out when posting the form. I posted a reply above about it working fine with the blank project. It seems to be something specific with the sample data and my server. I had another go with the start folder since then and tried various things like updating different packages one by one to match the symfony installer versions, changing session save path to match and other diferences I could see, but it always gves the same errors so I'm totally stumped. Need to move on now though.
I've been looking into FOSUserBundle regarding the different opinions about using it. There's some intense views out there!
In some conversations the KNPuGuard was mentioned (Which i assume was you guys) and that it is now part of Symfony 3 and that FOSUserBundle isn't really needed anymore.
Sooo, my question really is, should I stick with the Symfony 3 track to build my own, or go with the bundle and learn how to override and extend? (As a noob, wanting to get going, but also taking the right routes at the start if possible!)
I went through the same case and I ended using FOSUserBundle, because it gives you a lot of free functionalities, and if anything you don't like it, you can override it without too much problems, but, if what you want is to learn things, you should build your own
Thank Diego, I think that's probably the way I'm going to go. From the Symfony 3 track, it seemed pretty easy to roll your own, but when I think about all the extra bits like email notifications and forgotten passwords I think it's probably going to take more time than I initially thought. Time that could go into the actual main point of the app :)
I installed a blank project (3.3) with the symfony installer (and added doctrine/doctrine-cache-bundle) and then went through the exact same steps and registration works as expected, the user is added to the database with an encrypted password.
I just started again from scratch with the start folder of the project files taking the same steps and got the same errors again when trying to register.
I'm not really sure where the problem is, but I'm going to try and continue the course using the blank project.
In Symfony 3.4 and FosUserBundle 2.0, add a service mailer into the fos_user config:
fos_user: db_driver: orm # other valid values are 'mongodb' and 'couchdb' firewall_name: main user_class: AppBundle\Entity\User service: # this lines mailer: fos_user.mailer.twig_swift # this lines from_email: address: "%mailer_user%" sender_name: "%mailer_user%
Look's like that for some reason you are still using the default mailer instead of "fos_user.mailer.twig_swift". Try clearing the cache "$ php bin/console clear:cache" I believe since Symfony 3.4 the templating service does not come out of the box (I may be wrong on this and if that's the case, for some reason you have it disabled) and the default mailer depends on it, so that's why you are getting that error
i'm working with symfony4.1 but it's not the same directory hierarchy in this project , plz i need help with project , i don't have alot of time . please can someoe help me
heyy @diego aguiar , thanks for replying , to be honest i'm new to symfony , i'm trying to make a E-learning website and while trying to implement FOSUser bundle i tryed to follow you through the video but but i don't have the same directory hierarchy , i don't know what to do , should I download your same project and try delete the content you have on the website of aquanote or download a virgin one . can you give me your email
i don't know if this is right , but can you do me a favor? i want to give me tips or steps or videos to use . for exemple should i use symfony 4.* or 3.* ? what should i do step by step , you'll save a life .
If you haven't use Symfony3 before, then is an excellent moment to start using Symfony4 (Because S4 has many structural changes) The first thing you should do is to get familiar with the framework and understand what it gives you. We are releasing a new serie about Symfony4, so I highly recommend you to watch it (https://knpuniversity.com/t... ) In our Symfony3 serie we have covered a lot more ground, and if there is a topic you want to learn, you can still watch it and learn many things, of course, there will be some differences, but for the majority you will be able to overcome them, or you can leave us a message on the comments.
So, after getting familiar with Symfony and watching our tutorials, then you can watch how Ryan implements an E-commerce site using Symfony + Stripe (https://knpuniversity.com/t... )
Oh, btw, Symfony docs are also a great place for undestanding the guts of the framework.
When does that happens ? Could you show me the stack trace or a bit more about the error you are getting ? I think you are just missing a library, try running "composer install" again
Cheers!
Please, log in to vote for this comment
|
Share Comment
"Houston: no signs of life" Start the conversation!
41 Comments
help please, i have this error:
Attempted to load class "User" from namespace "UserBundle\Entity".
Did you forget a "use" statement for e.g. "Symfony\Component\Security\Core\User\User", "Symfony\Bridge\Doctrine\Tests\Fixtures\User", "FOS\UserBundle\Model\User", "FOS\RestBundle\Tests\Fixtures\User" or "AppBundle\Entity\User"?
Hey ines
Look's like you just forgot to import that class. Check at the top of your file in the imports section, if you cannot see it in there, then just add it :)
Cheers!
Hi, my project doesn't have the app folder, because probably in the creation I have build a Symfony Skeleton and not a normal one. How can I do this steps with my project? I have tried to check for appkernel in the folder but the source code looks completly differente compareted to yours.
SOLVED
After doing php bin/console he said to me:
In CheckExceptionOnInvalidReferenceBehaviorPass.php line 86:
The service "fos_user.resetting.controller" has a dependency on a non-existent service "templating".
SOLVED
When I do:
php bin/console doctrine:migrations:diff
In AbstractMySQLDriver.php line 93:
An exception occurred in driver: SQLSTATE[HY000] [2002]
The connection could not be verified. Persistent computer rejection by
DESTINATION.
In PDOConnection.php line 31:
SQLSTATE[HY000] [2002]
In PDOConnection.php line 27:
SQLSTATE[HY000] [2002]
Hey Gballocc7
About your DB problem "Persistent computer rejection by DESTINATION" - Wow, that's an interesting error. What's your DB system, MySQL?
Verify your DB connection, in Symfony4 you should define your connection string in an environment variable named "DATABASE_URL". Something like this
Also, verify that your DB server is up and running
Cheers!
Sorry for late I temporany left the project due to another project deadlines. So I followed this tutorial:
https://symfony.com/doc/current/doctrine.html
So I have configured the .env putting a password and a server name, but when I try to create a server using
php bin/console doctrine:database:createIt prints me the same error as written before: "Persistent computer rejection by DESTINATION"
Do I have to set a local db using MySql? I have never used before MySql, so I would like to know if it's possibile to use PostgreSql with Symfony/Docrine.
Ohh, so you are using a third party for your Database, like RDS from Amazon? If that's the case, you can use it, you only have to tweak the connection string
> Do I have to set a local db using MySql? I have never used before MySql, so I would like to know if it's possibile to use PostgreSql with Symfony/Docrine.
Symfony doesn't care about which DB engine you use, but Doctrine does. I'm not sure if Doctrine supports Postgres but you may want to do a quick search about it. Anyway, using MySql is pretty easy, so you may want to give it a try ;) (And, yes, you would have to set up a local MySql server)
Cheers!
done smooth no problem and error :) i wanna ask question can i alter router annotation when the user done register? or like i wanna change the router from localhost/register into bookstore/register
Hey Lavin Bassam!
Yep, you should be able to control this. The routes (and URLs) are provided by the bundle itself. However, when you import the routes, you are able to add a "prefix". Normally, you import ALL of the routes at the same time - https://symfony.com/doc/master/bundles/FOSUserBundle/index.html#step-6-import-fosuserbundle-routing-files
But, instead of importing all.xml, you can include each of the routing files one-by-one. And when you do THAT, you can add a prefix to the registration.xml import - https://symfony.com/doc/master/bundles/FOSUserBundle/routing.html
Let me know if that helps! If you want to redirect to a different URL after a successful registration, the best way to do that is to listen to the REGISTRATION_COMPLETED event. You will be passed a FilterUserResponseEvent object, and you can create a new RedirectResponse to a different url and call
$event->setResponse()to set your new Response on that object.If any of this doesn't make sense, let us know.
Cheers!
thanks for free videos !!
Running Symfony 4.1 and found the doctrine:migrations:generate and diff commands just created migrations with VOID inside (ie there was no SQL), so then running migrate would create/update the migration version table but not create the users table. However running doctrine:schema:update --force and it worked!!! Is this a Symfony 4 thing, or could I have done something wrong?
Hey Timothy J.!
Hmm, that is super strange! Well, sort of strange :). The doctrine:migrations:generate always creates empty migrations. But, the doctrine:migrations:diff command "should" (with quotes... because sometimes surprises happen in tech!) behave the exact same way as doctrine:schema:update. In fact, they use the same code behind the scenes to determine what queries to generate.
So, question time :).
1) Are you sure you tried running doctrine:migrations:diff?
2) Can you still repeat this? Like, if you drop your database and run doctrine:migrations:diff, is it still empty?
There's nothing special related to Symfony 4 for all of this. It's *possible* there's some misconfiguration... but I really can't imagine what it is!
Cheers!
Can you tell me please the plugins for the sublime text you are using? The new file plugins which let you add different types of files with the right button. Thank you.
Hey cescou
For this course (and actually for every course) Ryan uses PhpStorm as his text editor. I'm not sure if there exists the same plugins for Sublime as in PhpStorm, but maybe they do?
Have a nice day
Thank you! I need to buy new glasses ;)
Following along with the new fosuserbundle tutorial. The command .'/bin/console doctrine:migrations:diff' throws a command not found exception. The note says to install the DoctrineMigrationsBundle. Following this link the said mentioned command is again listed and results in the same error. Help I'm stuck in an endless loop LOL.
Hey Kim,
You're right, the command is valid. But did you install the DoctrineMigrationsBundle properly? :) There're a few steps you need to do to install it by following that link:
1. Require this bundle with "$ composer require doctrine/doctrine-migrations-bundle"
2. Add "new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle()," line to the app/Kernel.php file to register the bundle.
And then "./bin/console doctrine:migrations:diff" should work well.
Cheers!
Where can I learn more about ajax login/register (in modal windows)?
Hey Alexey,
Unfortunately, we do not have exactly this screencast, but I have a few link where you can find useful for you information:
- https://knpuniversity.com/s... - here's how you can send forms via AJAX.
- https://knpuniversity.com/s... - here's how you can handle an AJAX response.
So along the next screencast https://knpuniversity.com/s... you can create and render your login/register forms, but then intercept their sending with JS and send data with AJAX to the controller where you handle the request and return a JSON response for example which will say was the login/register successful or form has some errors. You can also do it along FOSUserBundle https://knpuniversity.com/s... , but probably you'll need to customize some third-party code by overriding it because FOSUserBundle does not work via AJAX out-of-the-box, so it could be more complex because you'll need to customize their actions, or write completely new ones.
Cheers!
Ok, thank you a lot!
Awesome tutorial, there's a possibility to use xml mapping instead of annotation in User entity?
Hey marlenesco
Of course is possible, but I would recommend you to use "yaml" instead of "xml", well, because, no body enjoys reading xml
If you have "auto_mapping" enabled (this is a default), then you just have to store your files inside "Resources/config/doctrine" (in your bundle) and Symfony will find them, but do not try to use more than one type of mapping, because Symfony reads only one type of mapping.
You can get more detailed information here: https://symfony.com/doc/3.3...
Cheers!
I'm getting an error when trying to register a user. It looks like the password fiedls aren't getting registered:
Hey Robert,
Hm, most likely this error is due to unfired event listener from FOSUserBundle which encodes plain password and sets the encoded password with User::setPassword() (IIRC the password is encoded and set in event listener in FOSUserBundle). Do you get this error in the prod environment? Because to update configuration you need to clear the prod cache after you install and configure the FOSUserBundle. You said you had got the same error with our downloaded Course Code. Did you update our code from the finish/ directory to Symfony 3.3 ? Because I can't reproduce it by myself: I downloaded the Course Code, went to the finish/ dir, installed composer dependencies, created DB, ran migrations, loaded fixtures, ran the Symfony web server, then went to /register page in dev environment and registered new user without any errors. Im I missing some steps? And one more question, what PHP version do you use? I tested it on PHP 7.1.5.
Cheers!
Hi,
Those are the exact steps I took with the finish folder. Just installed, not updated (Although I did try updating later on but the error wwas the same).
I'm running php 7.1.3, same error in prod
Just about to try the same steps with a blank symfony project and see if that's the same.
I had no issues with the security chapter of the symfony 3 course.
Let us know what you find out! It's weird because - if the bundle is not installed in composer or in
AppKernel, then you won't even be able to get to/registerat all. The fact that you could get there... but it failed on submit... that's the strange part ;).Cheers!
Hi Ryan,
I did install the FOSUserBundle and go through all the steps, it just errored out when posting the form.
I posted a reply above about it working fine with the blank project. It seems to be something specific with the sample data and my server.
I had another go with the start folder since then and tried various things like updating different packages one by one to match the symfony installer versions, changing session save path to match and other diferences I could see, but it always gves the same errors so I'm totally stumped.
Need to move on now though.
Hey Ryan,
I've been looking into FOSUserBundle regarding the different opinions about using it. There's some intense views out there!
In some conversations the KNPuGuard was mentioned (Which i assume was you guys) and that it is now part of Symfony 3 and that FOSUserBundle isn't really needed anymore.
Sooo, my question really is, should I stick with the Symfony 3 track to build my own, or go with the bundle and learn how to override and extend? (As a noob, wanting to get going, but also taking the right routes at the start if possible!)
Hey Robert
I went through the same case and I ended using FOSUserBundle, because it gives you a lot of free functionalities, and if anything you don't like it, you can override it without too much problems, but, if what you want is to learn things, you should build your own
Cheers!
Thank Diego,
I think that's probably the way I'm going to go.
From the Symfony 3 track, it seemed pretty easy to roll your own, but when I think about all the extra bits like email notifications and forgotten passwords I think it's probably going to take more time than I initially thought. Time that could go into the actual main point of the app :)
Exactly! Let's focus in what's more relevant to the project, if you can fill any gap with third party bundles, just do it :)
I installed a blank project (3.3) with the symfony installer (and added doctrine/doctrine-cache-bundle) and then went through the exact same steps and registration works as expected, the user is added to the database with an encrypted password.
I just started again from scratch with the start folder of the project files taking the same steps and got the same errors again when trying to register.
I'm not really sure where the problem is, but I'm going to try and continue the course using the blank project.
Help please, i have this message:
In CheckExceptionOnInvalidReferenceBehaviorPass.php line 32:
The service "fos_user.mailer" has a dependency on a non-existent service "templating".
I use Symfony 3.4
In Symfony 3.4 and FosUserBundle 2.0, add a service mailer into the fos_user config:
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: AppBundle\Entity\User
service: # this lines
mailer: fos_user.mailer.twig_swift # this lines
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%
Hey eandres
Look's like that for some reason you are still using the default mailer instead of "fos_user.mailer.twig_swift". Try clearing the cache "$ php bin/console clear:cache"
I believe since Symfony 3.4 the templating service does not come out of the box (I may be wrong on this and if that's the case, for some reason you have it disabled) and the default mailer depends on it, so that's why you are getting that error
I hope it helps you even a bit. Cheers!
i'm working with symfony4.1 but it's not the same directory hierarchy in this project , plz i need help with project , i don't have alot of time . please can someoe help me
Hey Amin Gharbi
Can you give us some context about your current problem?
Cheers!
heyy @diego aguiar , thanks for replying , to be honest i'm new to symfony , i'm trying to make a E-learning website and while trying to implement FOSUser bundle i tryed to follow you through the video but but i don't have the same directory hierarchy , i don't know what to do , should I download your same project and try delete the content you have on the website of aquanote or download a virgin one . can you give me your email
i don't know if this is right , but can you do me a favor? i want to give me tips or steps or videos to use . for exemple should i use symfony 4.* or 3.* ? what should i do step by step , you'll save a life .
If you haven't use Symfony3 before, then is an excellent moment to start using Symfony4 (Because S4 has many structural changes)
The first thing you should do is to get familiar with the framework and understand what it gives you. We are releasing a new serie about Symfony4, so I highly recommend you to watch it (https://knpuniversity.com/t... )
In our Symfony3 serie we have covered a lot more ground, and if there is a topic you want to learn, you can still watch it and learn many things, of course, there will be some differences, but for the majority you will be able to overcome them, or you can leave us a message on the comments.
So, after getting familiar with Symfony and watching our tutorials, then you can watch how Ryan implements an E-commerce site using Symfony + Stripe (https://knpuniversity.com/t... )
Oh, btw, Symfony docs are also a great place for undestanding the guts of the framework.
Cheers!
Can't find ORM Class in the generate menu :(
Hey Islam!
When does that happens ? Could you show me the stack trace or a bit more about the error you are getting ?
I think you are just missing a library, try running "composer install" again
Cheers!
"Houston: no signs of life"
Start the conversation!