2010-03-30 34 views
1

我幾乎失去它,我真的希望有人能幫助我!PHP主義沮喪:加載模型不起作用..?

我在CodeIgniter中使用Doctrine。一切都設置正確,直到我生成類和查看網站的作品。

Fatal error: Class 'BaseObjecten' not found in /var/www/vhosts/domain.com/application/models/Objecten.php on line 13

我用下面的引導程序(如CodeIgniter的插件):

<?php 
// system/application/plugins/doctrine_pi.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 
spl_autoload_register(array('Doctrine', 'autoload')); 

// 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 
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)); 
?> 

有人嗎?

p.s.我也嘗試在//(可選配置)之後加上以下內容:

Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE); 
spl_autoload_register(array('Doctrine', 'modelsAutoload')); 

回答

2

試過了嗎?

<?php 

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'); 

此外,根據您的服務器平臺,您可能希望使用xdebug和支持實時斷點的IDE檢出。該組合允許您通過在具有依賴性問題的classdef的第一行中設置斷點來相對快速地追蹤大多數自動加載器問題。

+0

我發現自己在Core.php中挖。但是你是對的。它與loadModels()函數的位置有關。 – Ropstah 2010-03-31 21:53:39

+0

@ropstah很高興爲你工作。 – David 2010-04-01 19:35:44

+1

@ropstah在Code Igniter中使用Doctrine的另一個建議是......除非您訪問Doctrine_前綴類,否則嘗試使用Doctrine :: getTable(「SubjectMatter」)來獲取SubjectMatterTable.php。如果其他人在試圖弄清楚你正在使用的內容時是否正在閱讀你的代碼,它會將混淆最小化。 – David 2010-04-02 16:28:07

2

只是一個小黑客

添加此行

Doctrine::loadModels(APPPATH.'/models/generated');

前...

Doctrine::loadModels(APPPATH.'/models');

或者你認爲你自動生成的基類的都在 應用其他路徑/helper/doctrine_pi.php