Undefined property: Purchase::$purchase_model codeigniter - php

This is the most strange error I have seen in my life, because yesterday it was working and I wake up today and it's not working this is the error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Purchase::$purchase_model
Filename: controllers/purchase.php
Line Number: 67
Here is the controller code
class Purchase extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->model('purchase_model', 'user_model');
$this->load->helper(array('form', 'url'));
$this->load->library(array('form_validation', 'upload'));
}
function steptwo()
{
if($this->input->post('templateid') == NULL){
redirect('templates');
}
$data =$_POST;
if($this->session->userdata('userName')){
$data['name']=$this->session->userdata('userName');
}else{ $data['name'] = NULL;}
$data['paymentplans'] = $this->purchase_model->GetPplan(array('id_template_type' => $_POST['idtype']));
$this->load->view('step-two', $data);
}
An here is my model code:
class Purchase_Model extends CI_Model
{
function GetPplan($options = array())
{
// Qualification
if(isset($options['id_template_type']))
$this->db->where('id_template_type', $options['id_template_type']);
// limit / offset
if(isset($options['limit']) && isset($options['offset']))
$this->db->limit($options['limit'], $options['offset']);
else if(isset($options['limit']))
$this->db->limit($options['limit']);
// sort
if(isset($options['sortBy']) && isset($options['sortDirection']))
$this->db->order_by($options['sortBy'], $options['sortDirection']);
$query = $this->db->get("template_payment_plan");
if(isset($options['count'])) return $query->num_rows();
if(isset($options['template_payment_planid']) || isset($options['detail']))
return $query->row(0);
return $query->result();
}
}
I already have done this $autoload['libraries'] = array('database', 'session'); so I don't think this was the problem.
If anyone know what can the error be I'll be really grateful

$this->load->model('purchase_model', 'user_model');
Here you load purchase_model that you call user_model, if you want load two models, make this :
$this->load->model('purchase_model');
$this->load->model('user_model');

Related

Fatal error: Call to undefined function customerslist() in C:\xampp\htdocs\CI\application\controllers\Customer.php on line 25

AM trying to connect modal in controller but it showing error like
Fatal error: Call to undefined function customerslist() in C:\xampp\htdocs\CI\application\controllers\Customer.php on line 25
A PHP Error was encountered
Severity: Error
Message: Call to undefined function customerslist()
Filename: controllers/Customer.php
Line Number: 25
Backtrace:
My code is following:
controller : Customer.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Customer extends CI_Controller {
public function __construct(){
parent:: __construct();
$this->load->library('form_validation');
$this->load->model('admin');
$this->load->model('customers');
}
public function index()
{
if($this->session->userdata('Admin')==false)
{
redirect('login');
}
else
{
$data['title'] = "Customer";
$data['customerlist'] = $this->customers>customerslist();
$this->load->view('customer',$data);
}
}
}
Modal: Customers.php
<?php
class Customers extends CI_Model {
function __construct()
{
parent::__construct();
}
//view all Customers
function customerslist()
{
$res = $this->db->get('customers_list');
if($res->num_rows() >0){
foreach($res->result_array() as $row){
$customerlist[] = $row;
}
return $customerlist;
}
else
{
return false;
}
}
//view all Customers
}
How can i fix this issues?
Thanks in advance....
You're missing a - in $this->customers>customerslist();
This should be $this->customers->customerslist();

HMVC model cannot be loaded SAYS Message: Undefined property:

hi i am currently working on a second module of my hmvc file and there comes an error that i think it wont load the models of this module. the previous modules models, works fine. what may be the error of this one? here is my codes.
error
Severity: Notice
Message: Undefined property: CI::$lEmploymentStatus_Model
Filename: MX/Controller.php
Line Number: 59
Backtrace:
File: C:\xampp\htdocs\TLC_HR\application\third_party\MX\Controller.php
Line: 59
Function: _error_handler
File: C:\xampp\htdocs\TLC_HR\application\modules\EmploymentStatus\Controllers\EmploymentStatus.php
Line: 43
Function: __get
File: C:\xampp\htdocs\TLC_HR\index.php
Line: 292
Function: require_once
controller - EmploymentStatus.php
<?php
class EmploymentStatus extends MY_Controller{
public function __construct(){
parent::__construct();
}
// VIEW REDIRECTING /////////////////////////////////////////////////////////
public function index(){
$data['content_view'] = 'EmploymentStatus/empstat_read';
$this->templates->admin_template($data);
}
public function add_view(){
$data['content_view'] = 'EmploymentStatus/add_view';
$this->templates->admin_template($data);
}
// CREATE /////////////////////////////////////////////////////////
public function create(){
$this->load->library('form_validation');
$this->load->model('EmploymentStatus_Model');
$this->form_validation->set_rules('ES_NAME','Name','trim|required|min_length[2]|max_length[20]');
$this->form_validation->set_rules('ES_DESCRIPTION','Description','trim|required|max_length[50]');
if($this->form_validation->run() == FALSE){
$this->add_view();
}else{
if($query = $this->lEmploymentStatus_Model->insert()){
$this->add_view();
}else{
$this->add_view();
}
}
}
}
?>
model - EmploymentStatus_Model.php
<?php
class EmploymentStatus_Model extends CI_Model{
///// CREATE /////////////////////////////////////////////////////////
public function insert(){
$input = array(
'ES_NAME' => $this->input->post('ES_NAME'),
'ES_DESCRIPTION' => $this->input->post('ES_DESCRIPTION')
);
$insert = $this->db->insert('employment_status',$input);
return $insert;
}
}
?>
it works perfectly fine. It just have a typo.
if($query = $this->lEmploymentStatus_Model->insert()){
$this->add_view();
lEmploymentStatus must be EmploymentStatus

Controller - Model in CodeIgniter and "Undefined property"

<?php
class Success_model extends CI_Model
{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
//insert into user table
function get_all()
{
$query = $this->db->get('session'); // = select * from session
return $query->result();
}
}
<?php
class Success extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->helper('url');
$this->load->model('success_model');
}
public function index()
{
$data= $this->Success_model->get_all();
$this->load->view('success_view', $data);
}
}
?>
As You can see this is good, but I have error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Success::$Success_model
Filename: controllers/success.php
Line Number: 15
Backtrace:
File: C:\xampp\htdocs\session\application\controllers\success.php
Line: 15
Function: _error_handler
File: C:\xampp\htdocs\session\index.php
Line: 292
Function: require_once
Fatal error: Call to a member function get_all() on null in C:\xampp\htdocs\session\application\controllers\success.php on line 15
A PHP Error was encountered
Severity: Error
Message: Call to a member function get_all() on null
Filename: controllers/success.php
Line Number: 15
Backtrace:
I'm looking, and looking, but I dont know what is bad. The good directories are files, other classes are working but this not.
Please help. I'm just tired, because after 2 hours searching mistakes...
For CI v3, afaik
I think I see it:
$data= $this->Success_model->get_all();
Should be:
$data = $this->success_model->get_all(); // Notice the lowercase success_model
PHP variables are case-sensitive where as functions and class names are not.
One more solution would be to change
$this->load->model('success_model');
into
$this->load->model('Success_model');
because then you can use
$data= $this->Success_model->get_all();

Getting error that Call to undefined function model() When I load to controller in CI framework

I just now learning codeigniter and this is my
model second_con.php
class second_con extends CI_Model
{ //CI version 3.0
public function second_mod()
{
$query = $this->db->query('SELECT * FROM subdepartment');
if($query->num_rows() > 0)
{
foreach($query->result() as $rows)
{
$datas[] = $rows;
}
return $datas;
}
}
}
controllers second.php
class second extends CI_Controller {
public function index() {
$this->load-model('second_con'); //line 7
$this->load->view('home1');
}
}
after this when I try to view this page. It showing error as follows. anyone can find out where I made mistake?
A PHP Error was encountered
Severity: Error
Message: Call to undefined function model()
Filename: controllers/second.php
Line Number: 7
Backtrace:
You are missing > in here load-model
This should be
$this->load-model('second_con'); # wrong
change to this
$this->load->model('second_con'); # correct

Need help on Codeigniter to solve an error on Controller and Model

Model/blogmodel.php:
class Blogmodel extends CI_Model {
public function get_recent_post($num){
$query = $this->db->get('wdr_blog_post', $num);
return $query->result();
}
}
Controller/blog.php:
class Blog extends CI_Controller {
public function index(){
$this->load->model('blogmodel');
$posts = $this->Blogmodel->get_recent_post(5);
}
}
Error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Blog::$Blogmodel
Filename: controllers/blog.php
Line Number: 7
Fatal error: Call to a member function get_recent_post() on a non-object in G:\server\htdocs\xyz\app\controllers\blog.php on line 7
Just guessing...
class Blog extends CI_Controller {
public function index(){
$this->Blogmodel = $this->load->model('blogmodel');
$posts = $this->Blogmodel->get_recent_post(5);
}
}

Categories