我一直在试用CodeIgniter。到目前为止,我喜欢。我决定也尝试一下理论,因为我听说了很多关于ORM的东西,而且这个理论很好。我找到了一些教程:
我已经尝试了所有的方法,我在那些尝试建立一个工作条令安装,但我仍然无法得到我的模型加载。所有这些文档中的一个共同点是,它们都是旧版本,引用了document和/或CI的旧版本,甚至连doctine自己的文档都引用了0.11版本。我使用的是CodeIgniter-1.7.2和document-1.2.3。
有人有最新的文件吗?有人能看出下面的代码哪里出错了吗?这是基于phpandstuff链接。
File Structure
root
\_system
\_application
\_config
\_controllers
\_models
\_views
\_plugins
\_doctrine
\_lib
\_Doctrine.php
\_doctrine_pi.php
系统/插件/条令_圆周率.php
// load Doctrine library
require_once BASEPATH.'/plugins/doctrine/lib/Doctrine.php';
// load database configuration from CodeIgniter
require_once APPPATH.'/config/database.php';
// this will allow Doctrine to load Model classes automatically
//below is the suggested method of loading models
//I also tried a user's suggestion of "modelsAutoload"
//spl_autoload_register(array('Doctrine', 'autoload'));
//spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
// we load our database connections into Doctrine_Manager
// this loop allows us to use multiple connections later on
foreach ($db as $connection_name => $db_values) {
// first we must convert to dsn format
$dsn = $db[$connection_name]['dbdriver'] .
'://' . $db[$connection_name]['username'] .
':' . $db[$connection_name]['password'].
'@' . $db[$connection_name]['hostname'] .
'/' . $db[$connection_name]['database'];
Doctrine_Manager::connection($dsn,$connection_name);
}
// CodeIgniter's Model class needs to be loaded
require_once BASEPATH.'/libraries/Model.php';
// telling Doctrine where our models are located
//Below is another user's suggestion, this also fails
//within my setup.
spl_autoload_register(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
Doctrine::loadModels(APPPATH.'models');
// (OPTIONAL) CONFIGURATION BELOW
// this will allow us to use "mutators"
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
// this sets all table columns to notnull and unsigned (for ints) by default
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_DEFAULT_COLUMN_OPTIONS,
array('notnull' => true, 'unsigned' => true));
// set the default primary key to be named 'id', integer, 4 bytes
Doctrine_Manager::getInstance()->setAttribute(
Doctrine::ATTR_DEFAULT_IDENTIFIER_OPTIONS,
array('name' => 'id', 'type' => 'integer', 'length' => 4));
从system/application/config/自动加载.php
/*
| -------------------------------------------------------------------
| Auto-load Plugins
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['plugin'] = array('captcha', 'js_calendar');
*/
$autoload['plugin'] = array('doctrine');
class User extends Doctrine_Record {
function __construct(){
parent::__construct();
}
function setTableDefinition(){
$this->hasDefinition("username", "string", 255);
$this->hasDefinition("password", "string", 255);
}
}
如果有人想见我的管制员或其他什么,请告诉我。
控制器只是
echo