After I finished studying and successfully passed the ZCE exam I knew I needed to move beyond playing around with WordPress, and after seeing a presentation by Ryan Weaver, I settled on learning Symfony2. Part of this decision was motivated by the fact that Symfony2 has embraced the very same changes in PHP introduced in 5.3 that I had studied for the ZCE, and did not want to forget... things like: namespaces, closures, and anonymous functions. Per the official SensioLabs definition: " Symfony2 is a reusable set of standalone, decoupled, and cohesive PHP components that solve common web development problems ."
And if you utilize Symfony's tight integration with Doctrine2 Object Relational Mapper, it fits the Model-View-Controller pattern.
Properties translate more or less to columns in a given MySQL table. These properties "or columns" are largely what you would expect them to be. In the first example of the Shopper model we have: Integer, string, string. There are special relationships, however, and these are the ones that tie these objects together, so that if you have one object you may easily query related objects (or rows) from other tables or even the same table.
This is the jist of the Shopper entity. It's missing the getters and setters, but those can be generated automatically via a console command. The last property of Shopper, orders, is a special property... it represents a special relationship between itself and another entity, in this case, the order entity. Whereas a string will be stored in the realname and streetaddress properties, the orders property will instead contain an array of the orders placed by the Shopper at one point or another. In this particular case a join column called shopper_id will be placed on the Orders table.
You can easily use these built in queries for most purposes, but it is important to know that you can also create your own custom queries using Doctrine's version of SQL syntax called DQL. If you do create your own, you can abstract them into a repository class so that the methods are accessible by the same means as these generic ones.
Previously I mentioned console commands that Symfony2 provides. These are just a few, and I do mean a few, of my favorites.
Twig is the templating engine utilized by Symfony2. This is the "view" part of the Model-View-Controller design pattern. It's syntax is very similar to the Python templating engine Jinja. It features some cool things such as template inheritance. You can see that if you were to render this particular template, it would also be rendering all of base.html.twig, which presumably contains a reference to a block called navigation which this child template is overriding.
This is a very basic example configuration of a route. It is utilizing a yml file, and provides optional requirements parameters that ensure that the route is only matched if the request utilized the GET HTTP method, and the end of the URL matches the regular expression which, in this case, only matches digits.
This example assumes that we have passed from our controller to the view a shopper object fetched from the database via doctrine.
This controller is about as simple as it gets. It uses the wildcard in the URL which was passed to the showAction function, grabs the shopper object from the database, and immediately passes it to the view.
So long as you've namespaced your classes using either t he technical interoperability standards for PHP 5.3, or the PEAR naming convention for class you can now use Symfony2's universal class loader to load your classes automatically when you use them.