• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter 2 can't extend CI_Model

#1
[eluser]Rui Lima[/eluser]
Hello,
I'm trying to extend CI_Model, but am unable to do it.

Code:
class MY_Model extends CI_Model{
        public function MY_Model(){
            $this->__construct();
        }    

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

    }

then when it gives me error:
Quote:Fatal error: Class 'MY_Model' not found in

Code:
class User_Model extends MY_Model{ //<--- can't fund MY_Model
    public function User_Model(){
        $this->__construct();
    }    

    public function __construct(){
        parent::MY_Model();
        $em = $this->doctrine->em;
        
        $this->load->library('encrypt');
    }
}

Any ideas? (this is CodeIgniter 2.0, i was able to do this with 1.7)

#2
[eluser]Jelmer[/eluser]
I'm guessing you've put the MY_Model.php file in application/libraries, which (as of CI2) isn't where it should go anymore.
CI2 split the libraries into core libraries and normal libraries, and CI_Model is considered a core library and as such should go in application/core.

#3
[eluser]Rui Lima[/eluser]
Yes i wasn't putting it on Core.
But when i put it there my application crashes

How should it be called:
MY_CI_Model extends CI_Model

MY_Model extends CI_Model

MY_CI_Model extends Model

MY_Model extends Model

I'm a bit confused Sad

#4
[eluser]Jelmer[/eluser]
It should be "class MY_Model extends CI_Model", like almost every CI included class extention.

But an application crash might be caused by anything, without the error message there's no way I could help you figure out what's wrong.

If you're not seeing an error, make sure you have the error_reporting function in your main index.php set to E_ALL or something like that. If you're still not seeing an error at that point add this just below the error_reporting() function:
Code:
ini_set('display_errors', 'On');

#5
[eluser]John_Betong[/eluser]
I have my model in the ./application/model/m_lib path and use autoload.php

&nbsp;
File: ./application/config/autoload.php
Code:
/*
| -------------------------------------------------------------------
|  Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
|    $autoload['model'] = array('model1', 'model2');
|
*/
$autoload['model'] = array('m_lib');
&nbsp;
&nbsp;
&nbsp;

#6
[eluser]Unknown[/eluser]
to solve. simply move MY_Model
from: /application/libraries
to: /application/core

thankyou Jelmer. Your reply save the day !

#7
[eluser]Unknown[/eluser]
thanks Jelmer.
Help me a lot!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.