簡體   English   中英

codeigniter 內核/型號.php 未定義屬性

[英]codeigniter core/model.php undefined property

我從未接觸過 model.php 文件,但是我收到了這個錯誤。 Jobprocess 是我的 controller 並且$lastname是在其中正確分配的變量。 我不知道為什么會出現這個錯誤。 這是使用 codeigniter 框架

Message: Undefined property: Jobprocess::$lastname

Filename: core/Model.php

Line Number: 50

確保在第 56 行的application/config/autoload.php上自動加載 model。

$autoload['libraries'] = array('database');

其次,確保 php 文件的名稱為小寫(mymodel.php),最后,確保 model class 名稱的第一個字母大寫

class Mymodel extends CI_Model{}

*Codeigniter Version 3 - Models must have a file name that begins with a capital letter: "Where Model_name is the name of your class. Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the基礎 Model class。” https://www.codeigniter.com/userguide3/general/models.html

$autoload['libraries'] = array('database'); 在 autoload.php 我在 codeigniter 上做 nettuts session 並花了兩個小時和 n 數量的雪茄,然后我終於想通了。

我更喜歡在我們編寫的 Model class 中加載數據庫,而不是通過配置文件自動加載它。
如下:

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

class fruits_model extends CI_Model {

private $fruits_table;

public function __construct()
{
    parent::__construct();
    $this->load->database();

    $this->fruits_table = 'fruits';
}

添加以下行,

$this->load->database();

在模型的構造函數中。

干杯!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM