当前位置:主页 > 软件编程 > PHP代码 >

laravel 如何实现引入自己的函数或类库

时间:2021-05-16 09:38:55 | 栏目:PHP代码 | 点击:

例如在app下建一个Common文件夹 在Common下建一个function.php 放入公共函数

例如:

  function test(){
    echo 'this is a test';
  }

在项目目录下composer.json中加入

"autoload": {
  "files":[
    "app/Common/function.php"
  ]
}

在项目目录下执行

composer dump-autoload

在控制器的某个方法中调用

public function aa(){
  test();  
}

您可能感兴趣的文章:

相关文章