dsgrs26202 2017-08-13 05:59
浏览 162
已采纳

如何在yii2中包含新的php文件/类?

i want to include pagination ajax class to yii2. how can i do that? when i use below code :

<?
    $url = Yii::app()->basePath.'/../vendor/phpunit/phpunit/src/Extensions/Pagination.php';
include $url;

?>

in controller and also below code:

require_once Yii::app()->basePath . '\..\vendor\phpunit\phpunit\src\Extensions\Pagination.php';

but both of them shows below error:

Call to undefined method Yii::app()

how can i fix it? is it true way to save pagination.php? please help me to include this file to my yii2 project..

thannks all :)

</div>
  • 写回答

1条回答 默认 最新

  • dongqiao9583 2017-08-13 06:01
    关注

    You are using the wrong access to yii2 components

    In yii2 you should use $app

    Yii::$app->->basePath
    

    and not Yii::app()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 YOLOv8已有一个初步的检测模型,想利用这个模型对新的图片进行自动标注,生成labellmg可以识别的数据,再手动修改。如何操作?
  • ¥15 怎么做商品窗体,完完全全不会
  • ¥30 NIRfast软件使用指导
  • ¥20 matlab仿真问题,求功率谱密度
  • ¥15 求micropython modbus-RTU 从机的代码或库?
  • ¥15 铜与钢双金属板叠加在一起每种材料300mm长,18mm宽,4mm厚一端固定并加热至80℃,当加热端温度保持不变时另一端的稳态温度。ansys
  • ¥15 django5安装失败
  • ¥15 Java与Hbase相关问题
  • ¥15 后缀 crn 游戏文件提取资源
  • ¥15 ANSYS分析简单钎焊问题