插件頁面上的代碼,我嘗試獲取構造函數中的文件------------------------------ -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- --------------------------------------------:Wordpress插件開發 - 如何從PHP OOP中的文件夾自動加載類?
<?php
/*
Plugin Page Code
*/
if(!class_exists('Tooo')) {
final class Tooo {
public function __construct()
{
require_once(plugin_dir_path(__FILE__) . 'admin/classes/class-file-loader.php');
}
}
}
$obj2 = new Tooo;
這是我的加載頁面代碼:
<?php
/**
* Autoloads testc classes using WordPress convention.
*
* @author testc Webdesign
*/
class testc_Loader
{
/**
* Registers testc Loader as an SPL autoloader.
*
* @param boolean $prepend
*/
public static function register($prepend = false)
{
if (version_compare(phpversion(), '5.3.0', '>=')) {
spl_autoload_register(array(new self, 'autoload'), true, $prepend);
} else {
spl_autoload_register(array(new self, 'autoload'));
}
}
/**
* Handles autoloading of testc classes.
*
* @param string $class
*/
public static function autoload($class)
{
if (is_file($class = plugin_dir_path(__FILE__) .'admin/classes/'.strtolower(str_replace(array('_', "\0"), array('-', ''), $class).'.php'))) {
include($class);
}
}
}
testc_Loader::register();
所以弄得不明白爲什麼它不包括。