1

I have two models: models/Categories.php and models/backend/BE_categories.php

I want BE_categories class to extend Categories, since it has some useful functions I can re-use:

Categories.php

class Categories extends CI_Model
{
...

BE_categories.php

class Be_categories extends Categories
{
...

But when $this->load->model('models/be_categories') I get the error: Unable to locate the specified class: Session.php yet it works with exending CI_Model What have I done wrong?

2
  • use BE_Categories as file-name and class-name, that should do it... Commented Mar 26, 2016 at 16:12
  • @Vickel Very nice spot, but it was a typo in the question..! Have edited Commented Mar 26, 2016 at 16:14

2 Answers 2

1

Just my guess, you load Session library inside some function in Categories model,and then try to use function with session library specific function inside model BE_Categories.

Add Session library in config/autoload.php or load it inside Categories model constructor, and remember to add constructor inside BE_Categories.

Sign up to request clarification or add additional context in comments.

Comments

1

I also had a Controller called Categories.php, with class Categories, which is where CI was getting confused.

I had to rename models/Categories.php to models/Categories_model.php as well as the class name.

But also had to include the file when extending:

BE_categories_model.php

include('application/models/Categories_model.php');
class Be_categories_model extends Categories_model
{
...

Edit:

Thanks to commenter, might be better to to include this model in config/autoload.php instead of using PHP's include() function.

5 Comments

Include in Codeigniter? It shouldn't be like that. Try to add models to application/config/autoload.php
@cssBlaster21895 Agreed it's not very 'CI', but if added to autoload, it will be loaded for every page adding unnecessary overhead?
It won't slow you down. Codeigniter is not heavy on resources. In one of last of my project's autoload, Ive added 9 libraries, 2 helpers and 7 models, and memory usage shows me around 0,65 mb used. Compare this to wordpress installations. F.e. usually server limit is 128mb, 64mb and Ive met wordpress advices to change that inside php.ini if you see "white screen of death". But that were the old times, I don't know how the wp situation looks nowadays.
@cssBlaster21895 Thank you, what does Codeigniter do if you autoload the model, and the load manually afterwards, does it check if it's been loaded before and ignore you?
It throws nothing, and probably(have to test) doesn't load twice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.