Thursday 15 January 2015

php - Codeigniter Extend custom model produces FATAL ERROR -


I have seen some different posts on this, but none of them is working for me.

I have a class that extends CI_Model:

  class Users_Model CI_Model {public function __construct () {parent :: __ construct (); }   

and afterwards:

  class Students_Model Users_Model provides {Private $ _students; Public function __ composition () {origin: __ creation (); $ This- & gt; _students = $ this- & gt; Get_students (); }   

However I receive this error message:

  PHP Fatal Error: Class 'Users_Model' / users / rosswilson / localhost / thedrumrooms / I I am using  need_once  to include the file in expanded category and it works. I Dreamweaver / ci / application / models / students_model.php   

What is the best practice / method to do this?

Thank you.

Standard practice in CI Application / Core Named MY_Model.php Within , MY_ is to create a base model that is defined in your configuration.

Then in your MY_Model.php you can have many classes defined in that file which you can increase in your model, basically the codeigner for classes defined on this route The load model of the file looks.

But if you want to use need_once , then you have to use APPPATH (the app path) < Code> index.php . But your custom model will still need to extend the CI_Model because it uses the core class for the CI model or your model will not work.

ex need_once APPPATH. / Model /test.php ';

By adding a note:

Thank you @ Din or to indicate it. should inside MY_Model.php file is a MY_Model class which increases CI_Model .

No comments:

Post a Comment