1

First of all, i'm using Kohana 2.3.4.

My question is, as Kohana docs says, Models must be in application/Models but to improve my app, I would like to have several sub-folders with other Models. This is useful because I can have a file tree more organized.

So, if I try to load a Model in a subfolder, 'class not found' error is returned, and if I move that class to main Model folder it works correctly.

So, my question is, how can i load the models in these subfolders?

Alex Coroza
  • 1,747
  • 3
  • 23
  • 39
andrealmeida
  • 91
  • 1
  • 3
  • 13

1 Answers1

0

IIRC, models are only auto-loaded from the base models/ path in kohana 2. You'd have to include the file by hand if you had it somewhere else:

require Kohana::find_file('models', 'path/to/model')

I think that's the right syntax. If it's not, just take a look at the kohana class.

zombor
  • 3,247
  • 17
  • 30
  • Yes, thats right: https://github.com/kohana/kohana2/blob/master/system/core/Kohana.php#L789 – biakaveron Jun 13 '12 at 18:34
  • Don't like very much that solution.. Isn't possible include that folder to be autoloaded, configuring inside kohana? – andrealmeida Jun 14 '12 at 14:22
  • Not without modifying the autoloader. You can do whatever you want then :) This is the "official" way to do it without modifying the framework. – zombor Jun 15 '12 at 01:56
  • You could also use modules to organise your models (and other related code) into separate folders, though these need to be included in your config. See here: http://docs.kohanaphp.com/general/modules – George Jun 28 '12 at 14:24