Welcome Guest, Not a member yet? Register   Sign In
Where to put plain object classes?
#38

(01-01-2015, 12:30 PM)includebeer Wrote: What? I don't know what you have done but you don't need to include anything to use a model!
You are incorrect, sir! If you want to extend CI_Model, you must either
a) include/require system/core/Model.php explicitly
OR
b) call $this->load->model() to get CI to require/include the CI_Model class for you.

To prove, try downloading a fresh CI3 from here:
http://www.codeigniter.com/download

Edit the Welcome controller so it's index function looks like this:
Code:
public function index()
        {
                require_once APPPATH . "models/Testmodel.php";
                $v = new Testmodel();
                $v->foo();
        }

And create a Testmodel class in application/models/Testmodel.php that contains this:
Code:
class Testmodel extends CI_Model {
  public function foo() {
    echo "congratulations! foo is running\n";
  }
}

The result:
Code:
Fatal error: Class 'CI_Model' not found in /path/to/CI/application/models/Testmodel.php on line 2
Reply


Messages In This Thread
Where to put plain object classes? - by geekita - 12-02-2014, 05:51 AM
RE: Where to put plain object classes? - by sneakyimp - 01-05-2015, 12:49 PM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 05:18 AM
RE: Where to put plain object classes? - by Jamie - 01-06-2015, 03:08 PM



Theme © iAndrew 2016 - Forum software by © MyBB