Creating a Symfony project from zero to success in 52 weeks (week 4.4.44 😉)
I want to thanks all the support this series of tutorials is receiving. I would like to make it clear that the title is not bait, I am really building this project from Saturday to Saturday and in real time along with the programming. I’m not even on the Medium Partner Program so I don’t make a dime for this. My only motivation is your readings, follows and claps.
I would like to share in each article my work as an amateur photographer. Please, if you see any worthwhile photos, I would appreciate it if you would follow me on Instagram.
Upgrade your User entity.
$ symfony console make:entity
Choose the User entity and add a ‘name’ field of type string, 255 characters length and false to nullable. This will store the real name of the user.
In addition to getRoles() and addRoles() we’ll add the addRole() method for adding a single role to the user:
Create a console command to add users. The login process is an important one in almost every application, but before you can sign in you need to have users in your database and since the registration process could be a bit complex it comes in handy to have a quick way to add security users to your project, and that way is a Symfony Console command.
$ symfony console make:command
I will name my command like app:user:create, you can replace ‘app’ by your application name, this is the scope of the command. Next is the subject (object, entity, etc.) of the action and finally is the action itself, so you can read the command from right to left like ‘create a user in app’. This is my personal methodology to name commands.
Check your newly created command in src/Command/AppUserCreateCommand.php. Below is mine:
Some considerations on the above command:
- I use the -s (super) option to add the user ‘Super Admin’ role (ROLE_SUPER). This user halts all the security restrictions we’ll use across the system in order to better debug and solve clients issues in the future.
- Later when we send emails we’ll upgrade this command to send the welcome email and maybe some email verification link.
Next week we’ll design the initial home page. Until the next Saturday!