Configuration ============= The first thing you need to know about Titi is that *you don’t need to define any model classes to use it*. With almost every other ORM, the first thing to do is set up your models and map them to database tables (through configuration variables, XML files or similar). With Titi, you can start using the ORM straight away. Setup ~~~~~ If you have used Composer to include Titi in your project, you can use the autoloader to provide access to the Titi namespace: .. code-block:: php 'value_for_setting_1', 'setting_name_2' => 'value_for_setting_2', 'etc' => 'etc' )); Use the ``get_config`` method to read current settings. .. code-block:: php 'mysql:host=localhost;dbname=my_database', 'username' => 'database_user', 'password' => 'top_secret' )); Result sets ^^^^^^^^^^^ Setting: ``return_result_sets`` Collections of results can be returned as an array (default) or as a result set. See the `find_result_set()` documentation for more information. .. code-block:: php true)); PDO Error Mode ^^^^^^^^^^^^^^ Setting: ``error_mode`` This can be used to set the ``PDO::ATTR_ERRMODE`` setting on the database connection class used by Titi. It should be passed one of the class constants defined by PDO. For example: .. code-block:: php 'person_id', 'role' => 'role_id', )); As with ``id_column`` setting, you can specify a compound primary key using an array. Limit clause style ^^^^^^^^^^^^^^^^^^ Setting: ``limit_clause_style`` You can specify the limit clause style in the configuration. This is to facilitate a MS SQL style limit clause that uses the ``TOP`` syntax. Acceptable values are ``ORM::LIMIT_STYLE_TOP_N`` and ``ORM::LIMIT_STYLE_LIMIT``. .. note:: If the PDO driver you are using is one of sqlsrv, dblib or mssql then Titi will automatically select the ``ORM::LIMIT_STYLE_TOP_N`` for you unless you override the setting. Query logging ^^^^^^^^^^^^^ Setting: ``logging`` Titi can log all queries it executes. To enable query logging, set the ``logging`` option to ``true`` (it is ``false`` by default). Model prefixing ~~~~~~~~~~~~~~~ Setting: ``Model::$auto_prefix_models`` To save having type out model class name prefixes whenever code utilises ``Model::for_table()`` it is possible to specify a prefix that will be prepended onto the class name. The model prefix is treated the same way as any other class name when the Model attempts to convert it to a table name. This is documented in the :doc:`models` section of the documentation. Here is a namespaced example to make it clearer: .. code-block:: php find_many(); // SQL executed: SELECT * FROM `tests_simple` Model::factory('SimpleUser')->find_many(); // SQL executed: SELECT * FROM `tests_simple_user` Model prefixes are only compatible with the ``Model::factory()`` methods described above. Where the shorter ``SimpleUser::find_many()`` style syntax is used, the addition of a Model prefix will cause ``Class not found`` errors. .. note:: Model class property ``$_table`` sets an explicit table name, ignoring the ``$auto_prefix_models`` property in your individual model classes. See documentation in the :doc:`models` section of the documentation. Model namespaces ~~~~~~~~~~~~~~~~ Setting: ``Model::$short_table_names`` Set as ``true`` to disregard namespace information when computing table names from class names. By default the class ``\Models\CarTyre`` expects the table name ``models_car_tyre``. With ``Model::$short_table_names = true`` the class ``\Models\CarTyre`` expects the table name ``car_tyre``. .. code-block:: php find_many(); // SQL executed: SELECT * FROM `car_tyre` namespace Models { class CarTyre extends Model { } } Further Configuration ~~~~~~~~~~~~~~~~~~~~~ The only other configuration options provided by Titi Models are the ``$_table`` and ``$_id_column`` static properties on model classes. To configure the database connection, you should use the ORM’s configuration system via the ``ORM::configure`` method. If you are using multiple connections, the optional `$_connection_key` static property may also be used to provide a default string key indicating which database connection in `ORM` should be used. Query logging ~~~~~~~~~~~~~ Titi can log all queries it executes. To enable query logging, set the ``logging`` option to ``true`` (it is ``false`` by default). .. code-block:: php