yii2:引用项目外的文件或类

yii2:引用项目外的文件或类

以项目:frontend为例,文件目录如下:

frontend/
    frontend/controllers
    frontend/views
    frontend/runtime
    ......

  

other/
    other/phpexcel/

   ......

在frontend/controllers/IndexController.php方法中:actionIndex中,引用 PHPExcel类:

$excelpath = dirname(Yii::$app->basePath).DIRECTORY_SEPARATOR.'weixin'.DIRECTORY_SEPARATOR.'phpexcel'.DIRECTORY_SEPARATOR;
        include_once $excelpath . 'PHPExcel.php';
        include_once $excelpath . 'PHPExcel'.DIRECTORY_SEPARATOR.'IOFactory.php';
        $excel     = new PHPExcel();

  

以上是正确引用,如果是require_once dirname(dirname(dirname(__FILE__))).'/other/phpexcel/PHPExcel.php';这样引用,是报错,找不到类:

Class 'frontactioncontrollersPHPExcel' not found

原文地址:https://www.cnblogs.com/achengmu/p/6596086.html