Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter core/model.php undefined property

Tags:

codeigniter

I have never touched the model.php 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
like image 773
triq Avatar asked Jul 19 '11 19:07

triq


3 Answers

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

like image 88
Max Avatar answered Oct 27 '22 06:10

Max


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

like image 41
Mad Scientist Avatar answered Oct 27 '22 05:10

Mad Scientist


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!

like image 27
Randika Vishman Avatar answered Oct 27 '22 05:10

Randika Vishman