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