PHP Doctrine的沮丧:加载模型不工作..? [英] PHP Doctrine frustration: loading models doesn't work..?
问题描述
我几乎失去了,我真的希望有人可以帮助我!
I'm almost losing it, i really hope someone can help me out!
我使用Doctrine与CodeIgniter。一切正常设置并正常工作,直到我生成类和查看网站。
I'm using Doctrine with CodeIgniter. Everything is setup correctly and works until I generate the classes and view the website.
致命错误:class'BaseObjecten' /www/vhosts/domain.com/application/models/Objecten.php on line 13
Fatal error: Class 'BaseObjecten' not found in /var/www/vhosts/domain.com/application/models/Objecten.php on line 13
我使用以下引导程序作为CodeIgniter插件):
I'm using the following bootstrapper (as CodeIgniter plugin):
<?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));
?>
任何人?
我也尝试在//(可选配置)之后添加以下内容:
Anyone?
p.s. I also tried adding the following right after // (OPTIONAL CONFIGURATION)
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::MODEL_LOADING_CONSERVATIVE);
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
推荐答案
试用?
<?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和支持活断点。该组合允许您通过在classdef的第一行设置一个断点来相对快速地跟踪大多数自动加载器问题,该断点具有依赖性问题。
Also, depending on your server platform, you might want to check out using xdebug and a IDE that supports live breakpoints. That combination allows you to track down most autoloader issues relatively quickly by setting a breakpoint on the first line of the classdef that has a dependency issue.
这篇关于PHP Doctrine的沮丧:加载模型不工作..?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!