I’m about to launch a website which I built with codeigniter3. I’ve made configuration changes such as base_url, database, etc. But it shows me an error like this :
JavaScriptxMessage: Undefined property: Home::$home
Filename: controllers/Home.php
Line Number: 18
Backtrace:
File: /home/u8460348/public_html/application/controllers/Home.php
Line: 18 Function: _error_handler
File: /home/u8460348/public_html/index.php Line: 294 Function:
require_once ```
JavaScriptMessage: Call to a member function select() on null
Filename: /home/u8460348/public_html/application/controllers/Home.php
Line Number: 18
Backtrace:
File: /home/u8460348/public_html/index.php Line: 294 Function:
require_once ```
So, here is my controller :
JavaScript
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Home extends My_Controller
{
public function index($page = null)
{
$data['title'] = 'Home | Omid Health Style';
$data['content'] = $this->home->select(
[
'product.id', 'product.slug', 'product.title AS product_title', 'product.description',
'product.image', 'product.price', 'product.is_available', 'product.weight',
'category.title AS category_title', 'category.slug AS category_slug'
]
)
->join('category')
->where('product.is_available', 1)
->paginate($page)
->get();
$data['total_rows'] = $this->home->where('product.is_available', 1)->count();
$this->home->table = 'blog';
$data['blogs'] = $this->home->select(
[
'blog.id', 'blog.slug', 'blog.title AS blog_title', 'blog.description', 'blog.content',
'blog.image', 'blog_category.title AS blog_category_title', 'blog_category.slug AS blog_category_slug'
]
)
->join('blog_category')
->paginate($page)
->get();
$data['total_rows'] = $this->home->count();
$data['page'] = 'pages/home/index';
$this->view($data);
}
}
Here is my Home_model.php :
JavaScript
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Home_model extends MY_Model
{
public $table = 'product';
protected $perPage = 8;
}
/* End of file Home_model.php */
And here is in my core folder, because i made a custom configuration like this :
JavaScript
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class My_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
$model = strtolower(get_class($this));
if (file_exists(APPPATH . 'models/' . $model . '_model.php')) {
$this->load->model($model . '_model', $model, true);
}
}
// Load view with Default Layouts
public function view($data)
{
$this->load->view('layouts/app', $data);
}
}
If I’m running the program in my localhost, it’s totally fine and works. Why do I get this error on a production server?
Advertisement
Answer
From the error message you received, the important part is
Message: Call to a member function select() on null
which means your model was not loaded!
as your code works on your localhost environment, but not on the production server, most likely the error is caused by applying wrong Naming Conventions:
- File names must be capitalized. For example: Myclass.php Class
- declarations must be capitalized. For example: class Myclass Class
- names and file names must match.