autoload.php:类的自动加载代码如下
<?php
function classLoader($class)
{
$path = str_replace('\\', DIRECTORY_SEPARATOR, $class);
$file = __DIR__ . DIRECTORY_SEPARATOR .'src'. DIRECTORY_SEPARATOR . $path . '.php';
if (file_exists($file)) {
require_once $file;
}
}
spl_autoload_register('classLoader');
1.将 autoload.php放在一个文件夹下(如:libraries/YLPAY)
2.将需要加载的类放在YLPAY文件夹下的src文件夹里
目录结构如下图:
3.使用:只要包含了autoload.php文件,则src文件夹里的类都会自动加载了,然后new加载的类就可以正常使用了
require_once APPPATH . "libraries/YLPAY/autoload.php";
$bean = new Req_bean;
$rsa = new Rsa($this->pfx_key, $this->pfx_pass);
$des = new Crypt3_des();
$des->setKey(base64_decode($this->generateKey(9999, 24)));