Skip to content

Instantly share code, notes, and snippets.

@paulchubatyy
Created September 9, 2010 12:21
Show Gist options
  • Save paulchubatyy/571796 to your computer and use it in GitHub Desktop.
Save paulchubatyy/571796 to your computer and use it in GitHub Desktop.
<?php
//....
Kohana::modules(array(
// 'database' => MODPATH.'database', //Database
// 'kodoc' => MODPATH.'kodoc', // Kohana documentation
// 'orm' => MODPATH.'orm', // Object Relationship Mapping (not complete)
'auth' => MODPATH.'auth', // Database access
'pagination' => MODPATH.'pagination', // Paging of results
'image' => MODPATH.'image', // Image manipulation
'doctrine' => MODPATH.'doctrine', // Doctrine ORM
);
<?php
return array(
'doctrine' => array(
'user' => 'username',
'password' => 'supersecretpasword',
'host' => 'localhost',
'database' => 'fancy_site',
'prefix' => 'wtfpl',
)
);
<?php
/* Doctrine integration */
require Kohana::find_file('classes', 'doctrine/Doctrine');
/* Реєструємо аутолоадер. Після розробки доктріну можна скомпілити в один файл
* розміров 800кб правда. Не думаю шо там можна шось сильно оптимізувати.
* Суть в тому, що треба виключити буде аутолоадер. якщо буде скомпілений файл.
*/
spl_autoload_register(array('Doctrine', 'autoload'));
// Читаємо конфіги для конекту з базою даних
$db = Kohana::config('database')->doctrine;
// Получаємо менеджер доктріни
$manager = Doctrine_Manager::getInstance();
//Створюємо конект
$manager->connection('mysql://'.$db['user'].':'.$db['password'].'@'.$db['host'].'/'.$db['database'], 'default_connection');
// @see http://www.doctrine-project.org/documentation/manual/1_1/en/configuration
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);
$manager->setAttribute(
Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS,
array('name' => '%s_id', 'type' => 'int', 'length' => 11)
);
$manager->setAttribute(Doctrine::ATTR_PORTABILITY, Doctrine::PORTABILITY_ALL);
$manager->setAttribute(Doctrine::ATTR_QUOTE_IDENTIFIER, true);
$manager->setAttribute(Doctrine::ATTR_EXPORT, Doctrine::EXPORT_ALL);
$manager->setAttribute(Doctrine::ATTR_TBLNAME_FORMAT, $db['prefix'].'_%s');
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
// Доктринові моделі будуть лежати не в classes/ а окремо в MODPATH
Doctrine::loadModels(APPPATH.'models');
<?php
//.....
Doctrine::loadModels(MODPATH.'blog/models');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment