Welcome Guest, Not a member yet? Register   Sign In
user model that extend a user model that extend CI_model
#1

[eluser]pyweb1[/eluser]
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

Code:
class User extends CI_model{
   ...
}
Code:
class Red_user extends User{
   ...
}

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

thx a lot!
#2

[eluser]InsiteFX[/eluser]
Code:
// 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{
   ...
}
#3

[eluser]pyweb1[/eluser]
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?
#4

[eluser]InsiteFX[/eluser]
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
#5

[eluser]pyweb1[/eluser]
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!
#6

[eluser]InsiteFX[/eluser]
Then you will need this, becuase CI will not read them all
Code:
/*
| -------------------------------------------------------------------
|  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
#7

[eluser]pyweb1[/eluser]
This is awesome! thx again, it look much more logical to be able to do that I think!




Theme © iAndrew 2016 - Forum software by © MyBB