【发布时间】:2012-06-14 13:49:05
【问题描述】:
我对 php 有了更深入的了解,我正在创建自己的 mini mvc 框架来学习 OOP。
我有一个将所有内容重定向到 index.php 的 .htaccess 文件。在 index.php 中,我包含一个名为 bootstrap.php 的文件来解析 url 并加载类 php 文件。
现在我正在添加 ActiveRecord http://www.phpactiverecord.org 以添加数据库访问权限。我得到了错误:
致命错误:无法在第 4 行的 /home/i554246/public_html/mvc/lib/Autoloader.php 中重新声明类 AutoLoader
我不确定如何停止冲突。
index.php:
include(MVC_CORE_INCLUDE_PATH . DS . 'Bootstrap.php')
include(MVC_CORE_INCLUDE_PATH . DS . 'activerecord/ActiveRecord.php');
bootstrap.php中包含的autoloader.php
<?php
class AutoLoader
{
public static function Load($Class)
{
$File = BASEDIR.$Class.'.php';
if(is_readable($File))
{
require($File);
}
else
{
die('Requested module "'.$Class.'" is missing. Execution stopped.');
}
}
}
spl_autoload_register('AutoLoader::Load');
ActiveRecord.php
if (!defined('PHP_ACTIVERECORD_AUTOLOAD_DISABLE'))
spl_autoload_register('activerecord_autoload',false,PHP_ACTIVERECORD_AUTOLOAD_PREPEND);
function activerecord_autoload($class_name)
{
$path = ActiveRecord\Config::instance()->get_model_directory();
$root = realpath(isset($path) ? $path : '.');
if (($namespaces = ActiveRecord\get_namespaces($class_name)))
{
$class_name = array_pop($namespaces);
$directories = array();
foreach ($namespaces as $directory)
$directories[] = $directory;
$root .= DIRECTORY_SEPARATOR . implode($directories, DIRECTORY_SEPARATOR);
}
$file = "$root/$class_name.php";
if (file_exists($file))
require $file;
}
?>
【问题讨论】:
标签: php phpactiverecord