EllisLab text mark
Advanced Search
     
user model that extend a user model that extend CI_model
Posted: 28 May 2012 07:46 PM
Joined: 2012-04-22
13 posts

hi,

a quick noob question because Google results are full of way to extends the core model CI_model and it’s polluting my result for my own query.

I want a model called user that extend CI_model and, let say, a sub model called red_user that extends user.

is it possible to do it and still have the user model ready to use alone. I have placed made my user model and put it in the model folder and i made another model

class User extends CI_model{
   
...
class Red_user extends User{
   
...

but a get an error saying that User can’t be found.

thx a lot!

 
Posted: 28 May 2012 07:52 PM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6583 posts
// you need to save this as ./application/core/MY_Model.php
class User extends CI_model{
   
...
}

// save as ./application/models/red_user.php
class Red_user extends User{
   
...

 

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 28 May 2012 08:23 PM   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-04-22
13 posts

ok thx,

it seem weird that my user class is now a core model of CI. Is there any more elegant way to do it without touching the codeigniter core?

should it be made possible to extends user defined class without changing the Codeigniter core structure?

 
Posted: 28 May 2012 09:15 PM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6583 posts

It’s not a core model it is extending the CI_Mode which is in ./system/core/Model.php

When you extend a Class thats is in ./system/core that class goes into ,/application/core
When you extend a Class thats in ./system/libraries then that Class goes into ./application/libraries

It’s the samething as extending the CI_Controller as a MY_Controller

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 28 May 2012 10:23 PM   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-04-22
13 posts

Ok, I think I understand!

my user class is in ./application/core/MY_Model.php because i want to extend it further and my red_user in ./application/model.

it seams a little bit arbitrary considering that I could always put everything in ./application/core/

and what if I want to extend (user extended (user extended (CI_model extended class)))...? all in the ./application/core/ but the last class that extends everything.

Thank you for your help again!

 
Posted: 28 May 2012 11:28 PM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2009-06-19
6583 posts

Then you will need this, becuase CI will not read them all

/*
| -------------------------------------------------------------------
|  Native Autoload - by Phil Sturgeon. New Version!
| -------------------------------------------------------------------
|
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
|
| If using HMVC you do not need this! HMVC will autoload.
|
| Place this code at the bottom of your application/config/config.php file.
*/
function __autoload($class)
{
    
if (strpos($class'CI_') !== 0)
    
{
        
if (file_exists($file APPPATH 'core/' $class EXT))
        
{
            
include $file;
        
}
        
elseif (file_exists($file APPPATH 'libraries/' $class EXT))
        
{
            
include $file;
        
}
    }

Read the comments

 

 Signature 

Certified State of CT Computer Programming Teacher.
Custom Designed Icons, eBook Covers Software Boxes. CD, DVD Etc. New iPhone® Tab Bar Icons and iPhone® Applications Icons.

Skype: insitfx

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

Input -> Controller | Processing -> Model | Output -> View

 
Posted: 29 May 2012 12:47 PM   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-04-22
13 posts

This is awesome! thx again, it look much more logical to be able to do that I think!