Reply to comment

Doctrine Usage On Zend Framework

doctrine logo In the last few months I used doctrine as ORM on my project. Actually, there are a few ORM on PHP like propel. But I like doctrine since the first sight, so I choose it as my ORM.

I decided to use ORM after work with database deployment with this technique that was so exhausting. With that technique we must make DDL script for each table, constraint, and also make DML script to insert dummy data. It was very tedious task.

Zend Framework LogoI will not explain or give snippets for doctrine usage on Zend Framework here, because it has been explain here dan here. On this post I just want to share how is my current problem can be solved with doctrine. If you don't know what is doctrine, maybe I will explain it on the next post.

Model And Table on Database
Zend Framework use MVC Pattern. To access tables on database we don't need to make query, but just make object from it's model. Without use doctrine, model and table on database must be created manually, after make table we must make model for it's table. Work with a few tables is not too problem. But how the project use 50 tables or even more? Very tedious and make a litle headache.
With doctrine, we just make description of table on schema file, and after that just run a litle command then model will be created automatically. And remember, model that created by doctrine is not inheritance from Zend_Db_Table. So to access all methods inside it you can see it's API.

Database Migration Between Each Release
On Agile methodology, project is released in several iterative. So that project is tested and implemented to client in several phase. We must implement database migration if there is any changing with database. Migration is intended to make change to database without destroy data have been exist on the project that implemented from previous release. This can do it with the technique that I mention before. It can do it with make DDL script first.
Doctrine do migration with make migration class first. But don't worry, we don't make it manually. Since doctrine 1.1.3, it can make it's own migration class with command. Those class is made with diff schema file with existing models. Then with another command doctrine make database migration with migration class that created before.

Universal Database
Zend_Db_Table also support universal database, but the table must be exist on database first. If not, we must convert old database, table and data type. We can do it manually or need help from another tools. With doctrine, convertion database easily. Because we don't need convert the database, table, and data type on the schema file. Doctrine will make change according to DSN that we used. So, we don't mind database migration in doctrine.

I think that's all story about doctrine usage on Zend Framework. I will post another story about doctrine on Zend Framework.

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options