【问题标题】:"Call to a member function library() on null" when use Library Upload Codeigniter 4使用库上传 Codeigniter 4 时“调用成员函数 library() on null”
【发布时间】:2022-01-02 06:09:58
【问题描述】:

当我上传我的文件时,我得到了这样的错误“调用一个成员函数 library() on null”...为什么?

这是我的观点

<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>

这是我的控制器

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');       
    }
}

我的构造

public function __construct()
{
    $this->panduan_model = new \App\Models\M_Panduan();
}

【问题讨论】:

  • 你能告诉我类定义和构造函数定义吗?

标签: codeigniter file-upload codeigniter-4


【解决方案1】:

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

public function __construct()
{
parent::__construct(); //don't forget this line
$this->panduan_model = new \App\Models\M_Panduan();
}

【讨论】:

  • 谢谢大家,我试过了,还是不行,最后我用了php move()
猜你喜欢
  • 2021-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-18
  • 1970-01-01
  • 2019-02-08
  • 2020-09-30
  • 2020-11-19
相关资源
最近更新 更多