Introduction To Models

From GeeklogWiki
Jump to: navigation, search

Yes, this will be just an introduction to models because we will later cover how to use Propel to generate models in detail. The model objects are classes that define or 'model' our business. So, in the case of Geeklog 2 we have a Gl2User model and a GL2Link model and so on. Even if you aren't using an Object Relational Mapping tool like we are, odds are you would have classes that define your models. It just so happens that in our environment, Propel generates those class files for us. How? Simple, Propel knows how to connect to a variety of database management systems and once connect to a database it can generate the PHP classes from the database model. Now it takes just a bit of work to get this going but it's not hard and not important for our immediate needs. For now, just know that for every table in Geeklog 2 there is a corresponding PHP class that models it with all the getters and setters.

So continuing with our Sample Contact Manager, we have been working with Contact class which is found in /path/to/sample/app/system/Propel/PHPARCH/Contact.php. If you open that up and inspect the methods, you'll find things like setFirstName(), getFirstName(), setLastName, getLastName, etc. But if you look even closer you'll see methods like getAddressRelatedByWorkAddressId(). That's right, Propel is smart enough to honor foriegn keys so you can get an objects involved in parent-child relationships. It is important to note that all this is code generated by Propel, not by developers.

I know a lot of magic seems to be occuring around the use of Propel and I promise it will all make sense in due time but before we discuss the details of Prople, let's finish up our MVCnPHP converage by talking about the MVCnPHP Controller.

Commands << previous   Next >> The MVCnPHP Controller
Geeklog 2 Wiki Homepage