codeigniter - 如何在 codeigniter 中包含供应商自动加载?
问题描述
我是 CodeIgniter 的新手,我只是想问一下如何在 CodeIgniter 中包含供应商/自动加载文件?我还没有尝试任何解决方案,所以也许有人可以帮助我解决这个问题?
解决方案
- 在您的配置文件中将composer 自动加载设置false更改为true。
$config['composer_autoload'] = TRUE;
- 将此行添加到您的index.php文件中。
include_once './vendor/autoload.php';
- 在库文件夹中创建库文件作为VendorLibrary.php。
代码
use Vendor\ClassName;
class ClassNameLibrary {
public $class;
public function __construct()
{
$this->class = new ClassName();
}
public function clear($data)
{
return $this->class->clean($data);
}
}
4.像这样在控制器中加载库。
代码
class HomeController extends CI_Controller {
public function __construct()
{
$this->load->library('classnamelibrary');
}
public function index()
{
$clean = $this->classnamelibrary->clear($data);
}
}
推荐阅读
- javascript - 为什么这个 jQuery parent("form") 不起作用
- deployment - 在 Vercel 上部署时找不到 404 页面上的错误代码 500
- rest - 用于保存和收藏项目的 RESTful API 端点结构
- android - Android 聊天分页会导致聊天屏幕向上跳到下一个分页
- git - 全局 Git 忽略不处理特定文件
- node.js - 在 Termux 中安装 sqlite3 时出错
- sql - Oracle 将使用 CTE 的工作 SQL 转换为过程
- c++ - 在同一行中声明和分配对象一些右值
- javascript - 水平和垂直条形图视图的按钮,但轴无法更改
- python - Python列表比较numpy优化