开发者

codeigniter core/model.php undefined property

开发者 https://www.devze.com 2023-03-21 05:28 出处:网络
I have never touched the model.php开发者_C百科 file, however I am getting this error. Jobprocess is my controller and $lastname is a variable assigned correctly within it. I have no idea why this erro

I have never touched the model.php开发者_C百科 file, however I am getting this error. Jobprocess is my controller and $lastname is a variable assigned correctly within it. I have no idea why this error is coming up. This is using codeigniter framework

Message: Undefined property: Jobprocess::$lastname

Filename: core/Model.php

Line Number: 50


Make sure to autoload model on application/config/autoload.php at line 56.

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

Second, make sure that the name of php file is lowercase (mymodel.php) and finally, make sure to capitalize the first letter of your model class name

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 base Model class." https://www.codeigniter.com/userguide3/general/models.html


$autoload['libraries'] = array('database'); in autoload.php I was doing the nettuts session on codeigniter and spent two hours and n number of cigerrates before I finally figured it out.


I prefer loading the Database within the Model class we write, than Auto-loading it via the Config files.
Like follows:

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

Add the following line,

$this->load->database();

Within the Model's constructer.

Cheers!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号