Tuesday, April 14, 2009
Posted by
fatearthling
at
6:22 PM
Using Propel ORM. My step-by-step walkthrough to create a working model:
There are several commands concerning the ORM which ultimately works toward building a Model.
The schema.yml, which represents the schema for a Model, can be either typed by hand, or imported and built directly from a database. To do so, type:
symfony propel:build-schema
Or if there is no corresponding database in the db, you may enter the schema by hand. After doing so, type
symfony propel:build-sql
to convert the schema into SQL commands. The actual SQL commands are stored in the lib.model.schema.sql inside the data/sql/ directory of the project folder. You can actually skip the build-sql step by editting this file directly...
After the build-sql command, you can insert the SQL commands into the db, provided that you have already configured the connection to your db. Use either
symfony configure:database "mysql:host=localhost;dbname=db_name"
or edit your
Once the connection to the db server are set, insert the SQL by typing:
symfony propel:insert-sql
This step will remove tables with the same names defined in the SQL in the db. Clearing Symfony cache is recommended after this step:
symfony cc
Then it's finally time to build Model so that we can use the ORM to access db:
symfony propel:build-model
Note: Actually, you MAY build Model directly from schema.yml, but it'd be pretty pointless without making sure your Model has a working db connection, right?
Labels: PHP, Symfony, Web Programming
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment