PHP CodeIgniter Error: Undefined Property [Generate Qrcode]

PHP CodeIgniter Error: Undefined Property [Generate Qrcode]

嗨,我刚开始在 codeigniter 上使用其他库(我使用这个 library)所以这些错误真的让我不知所措,我尝试的目标是使用选项标签(我的选项db)然后当我点击按钮时,它会自动生成二维码。一开始我是按照网上的一些教程,调整了一些部分以达到实际目标。

它没有在 html 页面上显示任何明确的错误,所以我检查了页面的控制台,错误如下;

jquery-3.4.1.js:9837 POST http://localhost/ikanku/Make_qr/save 500 (Internal Server Error)
send @ jquery-3.4.1.js:9837
ajax @ jquery-3.4.1.js:9434
(anonymous) @ make_qr:421
dispatch @ jquery-3.4.1.min.js:2
v.handle @ jquery-3.4.1.min.js:2

所以我试图打开网络选项卡以查看是否有任何我可以修复的东西,但它让我感到困惑,因为错误显示如下;

A PHP Error was encountered
Severity: Notice

Message: Undefined property: Make_qr::$Ciqrcode

Filename: core/Model.php

Line Number: 73

Backtrace:

File: C:\xampp\xampp\htdocs\ikanku\application\models\Make_qr_model.php
Line: 35
Function: __get

File: C:\xampp\xampp\htdocs\ikanku\application\controllers\Make_qr.php
Line: 24
Function: save

File: C:\xampp\xampp\htdocs\ikanku\index.php
Line: 315
Function: require_once

我已经通过自动加载全局加载模型名称,控制器名称并通过 parent::__construct(); 在内部加载但它仍然如上所示错误,我真的需要任何人的 suggestion/advice 来解决我的问题,因为我仍在学习如何在我的应用程序中制作二维码功能。 现在我正在使用 CodeIgniter 3.1.11

这是我的控制器 - Make_qr.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Make_qr extends CI_Controller {
    public function __construct()
    {
      parent::__construct();
      $this->load->model('Make_qr_model');
    }

    public function index()
    {
        $data['vessel'] = $this->db->query('select * from vessel order by vessel_name')->result_array();
        $data['port'] = $this->db->query('select * from port order by port_name')->result_array();
        $this->load->view('template/header');
        $this->load->view('template/sidebar');
        $this->load->view('qrcode/make_qr',$data);
        $this->load->view('template/footer');

    }

    public function save()
    {
        $this->Make_qr_model->save($this->input->post());
    }
}

这是我的模型 - Make_qr_model.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Make_qr_model extends CI_Model {
    function __construct()
    {
        parent::__construct();
        $this->load->library('Ciqrcode');
    }

    function random_strings($length_of_string){ 

        $str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; //abcdefghijklmnopqrstuvwxyz
        return substr(str_shuffle($str_result),0, $length_of_string); 
    }
//save data function setelah qrcode di generate
    public function save($data){
        $data = array_replace($data,
            array_fill_keys(
                array_keys($data, ""),
                NULL
            )
        );
        if(isset($data['quantity']) && count($data['quantity'])>0){
            for($i=1;$i<=$data['quantity'];$i++){
                $r = $this->random_strings(6);

                $this->load->library('Ciqrcode');

                $config['cacheable']    = true;
                $config['cachedir']     = './assets/';
                $config['errorlog']     = './assets/';
                $config['imagedir']     = './assets/images/';
                $config['quality']      = true;
                $config['size']         = '1024';
                $config['black']        = array(224,255,255);
                $config['white']        = array(70,130,180);
                $this->Ciqrcode->initialize($config);

                $image_name=$r.'.png'; //buat name dari qr code sesuai dengan random string

                $params['data'] = $r; //data yang akan di jadikan QR CODE
                $params['level'] = 'H'; //H=High
                $params['size'] = 1024;
                $params['savename'] = FCPATH.$config['imagedir'].$image_name; //simpan image QR CODE ke folder assets/images/
                $this->Ciqrcode->generate($params); // fungsi untuk generate QR CODE

                $img = file_get_contents(FCPATH.$config['imagedir'].$image_name, "r");


                $base64 = 'data:image/png;base64,'.base64_encode($img);

                $data_insert = array();
                $data_insert['vessel_id'] = $data['vessel_id'];
                $data_insert['port_id'] = $data['port_id'];
                $data_insert['key'] = $r;
                $data_insert['qr'] = $base64;
                $this->db->insert('qr_vessel', $data_insert);

                $vessel = $this->db->query('select * from vessel where id='.$data['vessel_id'])->row_array();

                echo "<table class='table table-striped m-table'>
<tbody>
    <tr>
      <td width='30%' style='background-color:black'>
        <img src=".$base64.">
      </td>
      <td width='70%' style='vertical-align:top'>
        Vessel Name : ".$vessel['vessel_name']."<br>
        Vessel Company : ".$vessel['company']."<br>
        Fishing Gear : ".$vessel['fishing_gear']."<br>
      </td>
    </tr>
    <tr>
      <td align='center'>
        ".$r."
      </td>
      <td align='center'></td>
    </tr>
</body>
</table>";
            }
            $notif['x'] = 'ok';
        }else{
            $notif['x'] = 'error';
            die('error');
        }

        return;

    }
}
?>

这是我的观点 - make_qr.php

<section class="content">
<form role="form" name="frm" action="<?=site_url('Make_qr/save')?>" method="post" id="frm">
<div id="container">
    <h1>Generate Fishing QR</h1>

    <div id="body">
        <table class="table table-striped m-table">
          <tbody>
            <tr>
              <td>Vessel</td>
              <td>
                <select id='vessel_id' name='vessel_id' style="width:250px" >
                    <option value="">Pilih</option>
                    <?php
                    foreach($vessel as $row){
                    ?>
                      <option value="<?=$row['id_vessel']?>"><?=$row['vessel_name']?> - <?=$row['company']?></option>
                    <?php
                    }
                    ?>
                </select>
              </td>
            </tr>

            <tr>
              <td>Port Departure</td>
              <td>
                <select id='port_id' name='port_id' style="width:250px" >
                    <option value="">Pilih</option>
                    <?php
                    foreach($port as $row){
                    ?>
                      <option value="<?=$row['id_port']?>"><?=$row['port_name']?></option>
                    <?php
                    }
                    ?>
                </select>
              </td>
            </tr>

            <tr>
              <td>QR Quantity</td>
              <td>
                <select id='quantity' name='quantity'>
                    <option value="">Pilih</option>
                    <?php
                    for($i=1;$i<=20;$i++){
                    ?>
                      <option value="<?=$i?>"><?=$i?></option>
                    <?php
                    }
                    ?>
                </select>
              </td>
            </tr>
          </tbody>
        </table>
        <div class="col-lg-3 m--margin-bottom-10-tablet-and-mobile">
            <span id='loading' style="display:none"><img src="<?php echo base_url(); ?>Assets/assets/images/ajax-loader_dark.gif"></span>
            <button type="button" class="btn btn-info" id="save">Generate</button>
        </div>
        <br>
        <div id='qrs'></div>
    </div>
</section>

我很抱歉对我的错误进行了冗长的描述,如果我能从这里得到一些建议和建议,那对我来说意义重大,

谢谢你

Change model name Make_qr_model to Makeqr_model

Load library $this->load->model('Makeqr_model');

Load CodeIgniter-PHP-QR-Code library properly; clone git repo and paste folder inside application/libraries

Make sure GD2 PHP extension installed

<?php 
defined('BASEPATH') OR exit('No direct script access allowed');



class QRGenerator extends CI_Controller {
    function __construct(){
       Parent::__construct();
    }


    public function generate(){
        $this->load->library('ciqrcode');

        $params['data'] = 'This is a text to encode become QR Code';
        $params['level'] = 'H';
        $params['size'] = 10;
        $params['savename'] = FCPATH.'tes.png';
        $this->ciqrcode->generate($params);

        echo '<img src="'.base_url().'test.png" />';
    }

}    


Codeigniter 模型参考 click

希望对您有所帮助