首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当使用Library Upload Codeigniter 4时"Call to a member function library() on null“

当使用Library Upload Codeigniter 4时"Call to a member function library() on null“
EN

Stack Overflow用户
提问于 2021-11-23 18:37:22
回答 1查看 44关注 0票数 0

当我上传我的文件时,我得到了这样的错误:"Call to a member function library() on null"...为什么?

这是我的观点

代码语言:javascript
复制
<div class="modal-body">
        <div class="form-group">
            <label>File PDF</label>
            <form method="post" id="form-upload" action="<?= base_url(); ?>/panduan/testing" enctype="multipart/form-data">
            <input type="hidden" name="type_proses" id="type_proses" />
            <input type="hidden" name="type_file" id="type_file" />
            <input type="file" name="file" class="form-control" id="file" required accept=".pdf" /></p>
        </div>
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    <button type="submit" class="btn btn-primary">Save</button>
  </div>
  </form>

这是我的控制器

代码语言:javascript
复制
public function testing()
{
    $file_name = 'tes';
    $config['upload_path'] = FCPATH.'/public/assets-menu/file/upload/panduan/';
    $config['file_name'] = $file_name;
    $config['allowed_types'] = 'pdf';

    $this->load->library('upload', $config);
    if (!$this->upload->do_upload('file')) {
        print_r('error');
    } else {
        $data = $this->upload->data();
        print_r('ok');       
    }
}

我的构造

代码语言:javascript
复制
public function __construct()
{
    $this->panduan_model = new \App\Models\M_Panduan();
}
EN

回答 1

Stack Overflow用户

发布于 2021-11-23 19:40:52

我不确定,也许您在构造时错过了这一行

代码语言:javascript
复制
public function __construct()
{
parent::__construct(); //don't forget this line
$this->panduan_model = new \App\Models\M_Panduan();
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70086155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档