in tutorials such as this http://akrabat.com/zend-framework-tutorial/, the database parameters for the application are stored in the application.ini config file. Reading through the docs for zend_db and other database interaction tutorials, it suggests that the database object is created from parameters hard coded into php code. Whats confusing is that there doesnt appear to be any explicit initialisation of the database object in tutorials such as the one above. So my natural conclusion to this is that the database object is automatically generated from the parameters provided in the application.ini config file?
Add a comment
|
1 Answer
So my natural conclusion to this is that the database object is automatically generated from the parameters provided in the application.ini config file?
Kind of, in fact, there are a few step before your database get initialized.
- Your application is bootstraped
- It reads the config file
- When a resource.* is found, check if the according resource class exists
- The resource class initialize an object with the given parameter
- Zend_Db_Table has a static method setDefaultAdapter($db) which takes the newly created Zend_Db object, now every Zend_Db_table object can use the Db object you set in your configuration.
- Return the newly created object
- Go back to 3.
- Router, Controller, Layout, View, etc.
This "behavior" is recent, it's why you may found some old tutorial which shows you how to bootstrap your Zend_Db object manually, sometimes, it's just to show you how Zend_Db works.
2 Comments
richzilla
ah right, so im assuming that anything under
resource.db, relates to an instance of the zend_db class?Jerry Saravia
yup!! If you check in the Zend/Application/Resource folder you'll see all the resource classes that come with Zend. When you see resources.* it'll go to this folder and look for the corresponding resource class and feed it the parameters it got from the .ini file. The class uses these to then create the actual object you'll use later.