2

I'm working on a calendar planning provided by [easyappointments][1] but now I'm stuck on this error by yesterday. In the main page users.php I've added the following:

<?php 
   require_once("application/models/impostazioni_model.php"); 

   $this->load->model('impostazioni_model');
   $this->impostazioni_model->load_colours();
?>

the require_once find correctly the file impostazioni_model.php but when I enter in the page users.php

I see this error:

Fatal error: Call to a member function load_colours() on a non-object

on this line: $this->impostazioni_model->load_colours();

in the class impostazioni_model.php I've this content:

<?php if ( ! defined('BASEPATH')) exit('Direct execution not allowed.'); 

class Impostazioni_Model extends CI_Model 
{
  public function __construct() 
  {
      parent::__construct();
  }


  public function load_colours()
  {
       echo "print";
  }

}

?>

I've followed the codeigniter documentation, in particular the class model must be in capital letter so I don't know what I'm wrong. Someone could help me out?

Dillinger
  • 1,823
  • 4
  • 33
  • 78

1 Answers1

1

In Controller

Path - application/controllers

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Admin extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('impostazioni_model'); //this will show "Print" word on browser. 
    }

    function index() {

    $this->impostazioni_model->load_colours();

    }

}

In Model

Path - application/model

<?php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');

    class Impostazioni_model extends CI_Model {

        function __construct() {
            parent::__construct();
        }

        function load_colours() {
            echo "print";
        }
    }
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85
  • One question: you said "application/controller" I've in my folder "application/controllers", which file I must edit? The same thing on "application/model" I've "application/model" I don't know which file must b edit. – Dillinger Oct 09 '15 at 13:00
  • Okay but in the controllers folder I doesn't have the file "admin.php" in which file is located the class "Admin"? The model "impostazioni" must be called in the file users.php, this file doesn't have any class and can't have a class 'cause is a mix of html, php and ajax request. This is my "user.php" file: http://pastebin.com/JA9QHmZd and is located in: root/application/controllers – Dillinger Oct 09 '15 at 13:31
  • No men. Change your controler name as ur need. I just post example – Abdulla Nilam Oct 09 '15 at 13:36
  • Okay now I've integrated the class inside the php file but how I can load the function of that class in the php file? – Dillinger Oct 09 '15 at 13:43
  • In controller check index function. Im calling method from model – Abdulla Nilam Oct 09 '15 at 14:05