私はphpをより深く理解し、OOPを学ぶために独自のミニmvcフレームワークを作成しています。
すべてを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;
}
?>