I’m writing this post for two reasons:
- So others can learn from my mistakes
- So I have this documented somewhere other than my laptop
This post is almost completely a copy and paste job of the notes I created while I was building my last project using Symfony 2.7.
I’ve found that it’s important to specify which SYMFONY_ENV you’re in when you’re running composer. I ran into a series of problems with I first went to install my dependencies on my production box. The fix has been specifying the SYMFONY_ENV:
I’m really loving Doctrine. I love how you can define the columns and relationships inside the models and how it easily creates all the related structures. It’s so much nicer than the horrible system I have of using MySQL Workbench to create schema files based on the differences.
Generate getters and setters
To have Doctrine generate the getters and setters you can run:
I’ve found the Doctrine Migrations Bundle to be very helpful. The Doctrine bundle doesn’t provide a way to add default data (information you might need for a select) so I started using this early in the project. I’m already a big fan of database versioning so it didn’t take much to get me onboard with this.
To create a diff file:
To apply a diff file
To create a blank migrations file (to create default data):
Random Helpful Commands:
I’ve found these to be helpful more than once.
Debug the Router:
Clear the Cache
Dump the assetic assets
In order to check if the current user has a role:
Twig Dump Function
I found this to be useful in figuring out what it was I was working with. It’s like php’s
Twig For Loop Variables
Twig provides several helpful variables for determining where you’re at in a loop. I’m not going to copy and paste it into this post because it can be found here:
Getting The Current User In a Controller
I don’t know why but this seemed overly complicated to me. I also ran into a lot of problems understanding the difference between IS_AUTHENTICATED_REMEMBERED and IS_AUTHENTICATED_FULLY.
Fill a Select With Values From a Database Table
I was shocked at how easy this was:
The important things to note are that ‘family’ is the name of the element, ‘entity’ is the type, ‘class’ indicates the entity, and ‘property’ indicates what’s the option inside the select.
Dynamical Adding Elements in a Form
Sadly this was complicated. To the point where I don’t every want to have to reiterate this and will just give you a link to more information.
FOS User Bundle
I think the FOS User Bundle saved me a bunch of time because I didn’t have to write my own login/registration system. The only thing I didn’t find easy was learning how to create a user account when you’re first setting up your site (so you have an admin account). It’s done with the following:
More information can be found at http://symfony.com/doc/current/bundles/FOSUserBundle/command_line_tools.html
Performance Problems Running in a VM
I’m running my development environment in a VM and I found the site to be sluggish to the point where I actually questioned my use of Symfony. To fix this problem I had to add the following to my AppKernel to improve the performance. These lines move the cache and the logs to a local directory.
Overall, I’m very happy I went with Symfony for this project even if there was a huge uphill climb to get the project up and running. I’m starting to work on another project and any future projects will be using Symfony.
Scott is the Director of Technology at WeCare Connect where he strives to provide solutions for his customers needs. He's the father of two and can be found most weekends working on projects around the house with his loving partner.
- Working With Soft Deletes in Laravel (By Example)
- Fixing CMake was unable to find a build program corresponding to "Unix Makefiles"
- Upgrading to Laravel 8.x
- Get The Count of the Number of Users in an AD Group
- Multiple Vagrant VMs in One Vagrantfile
- Fixing the "this is larger than GitHub's recommended maximum file size of 50.00 MB" error
- Changing the Directory Vagrant Stores the VMs In
- Accepting Android SDK Licenses From The OSX Command Line
- Fixing the 'Target class [config] does not exist' Error
- Using Rectangle to Manage MacOS Windows