DB_DataObject needs to be configured before using it and auto generating classes and definitions. The easiest way to configure DB_DataObject is to use ini files (although you may also like to consider the PEAR::Config class, or your own configuration system)
Пример 34-1. This is a typical configuration file for DB_DataObject
|
To use this ini file with DB_DataObject, (and possibly any other classes that use options like this)
Пример 34-2. Setting the default options
|
This is the default DSN to connect to your database
The directory where the DB_DataObject database schema file is store.
DB_DataObject stores the description of the database (Tables and Columns) in an .ini file, in this directory. This information is used to determine if the column is a string and needs quotes, or should be a number (and is checked) at SQL building time. It is quite common to store the schema in the same directory as your DataObject Classes.
The Path absolute, or relative to your default include path(s), where your extended classes can be found.
This is used by the staticGet() method and the getLinks() method to auto load classes,
All the generated Classes are named {class_prefix}ucfirst($table_name). Use this to alter the prefixed name, this is used by the staticGet() and getLinks() methods
To Hard code the key (autoincrement/nextval() for a table to a specific key ,overriding anything in the keys definition of the file. Normally used on databases that are not able to be queried correctly for their structure
Пример 34-3. using login as the key for the person table
|
If you do not want to use pear's nextval(), for automatically filling in sequences, this can disable it for "ALL", or a list of tables "person,cart,group"
The default debugging level (default 0=off), 1= basic sql logging,2=result logging, 3=everything
default FALSE, if set, then updates on the database are disabled.
default FALSE, The standard behaviour of dataobjects is to issue a PEAR_ERROR_DIE (eg. exiting PHP), when a fatal error occurs, like database connection failure or sending an invalid object type to a method. However if you need to run it on a live server you will probably want to set this to TRUE and define a PEAR error handler to catch these errors and show a nice friendly 'sorry we are down for maintenence' message page.
To force the quotation of identifiers in the SQL statements, set this to 1
Пример 34-4. Statement Generated with and without quote_identifiers
|
This enables the building of classes and ini classes on the fly, rather than forcing you to generate the code forhand. (currently the only value supported is "full", which will generate both schema data and default classes when using factory)
When you have multiple databases you can use the database_* to specify the DSN for each database
Пример 34-5. using multiple databases - database passwords
|
When you have multiple databases you can use the table_* configuration variables to map individual tables to different databases, for example
Пример 34-6. using multiple databases - table settings
|
The Directory where your DataObject extended Classes are.
Used by the Class Auto Builder when updating/writing to your class definitions.
The Name of your Base Class (usually DB_DataObject) is located.
If you wish to add a common layer of useful methods for all classes, you can set the extends_location and extends settings to a different class. the default is 'DB_DataObject'
The Directory where your Base Class (usually DB_DataObject) is located.
If you wish to add a common layer of useful methods for all classes, you can set the extends_location and extends settings to a different class. the default is 'DB/DataObject.php'
Normally when you recreate a class from the database, it will only alter the variables, and staticGet, - with this set, it will also update the extends field
Postgres (and maybe some others), allow you to treat views just like normal tables (eg. insert/update/delete etc. work on them), you can use this option to generate files for all the views in the database.
Note: You will have to specify keys manually in the generated classes (eg. define the methods keys() and sequenceKey(), as the generator can not guess which ones are likely to be the key.
If you only want to generate classes and ini entries for specific tables, you can use this to build a regex, only tables with names matching the regex will be generated, for example /mytables_.*/
If you only want to explicitly prevent the generation of classes and ini entries for specific tables, you can use this to build a regex, any tables that match the regex, will not be generated, for example /private_tables_.*/
postgresql has a wierd concept of schemas which end up prefixed to the list of tables. - this makes a mess of class/schema generation setting this to 1, makes the generator strip the schema from the table name
If True, the generator does not write a private or var's definition for the columns so you can overload get/set.
If True, the generator will insert / (or add to existing files) stubs for validate methods.
Пред. | Начало | След. |
Introduction | Уровень выше | Auto Building and Database Schema |
HIVE: All information for read only. Please respect copyright! |