码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-03-21 19:37:12      阅读:366      评论:0      收藏:0      [点我收藏+]

标签:require   nbsp   view   div   app   clu   bsp   weixin   tac   

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 ‘frontaction\controllers\PHPExcel‘ not found

 

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

标签:require   nbsp   view   div   app   clu   bsp   weixin   tac   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!