Welcome Guest, Not a member yet? Register   Sign In
Load Model in subdirectory (3 level)
#1

[eluser]csotelo[/eluser]
Hello, I have the following structure in the Models folder

-Models/
--admin/
---quotes/
----product_model.php
--web/

The problem is I want to load the model "product_model" in quotes folder, but it shows me the error:

$this->load->model('admin/quotes/product_model');

Quote:Unable to locate the model you have specified: product_model

But when I change the file position:

-Models/
--admin/
---product_model.php
--web/

....functioning properly

Only accepts 2 levels of load? It is possible to fix this?
I hope your help.


#2

[eluser]CroNiX[/eluser]
I know there is a limitation for controllers but didn't realize it affected models as well. Then again, I've never needed to use more than one level down.
#3

[eluser]Fireclave[/eluser]
Look in the Loader.php in the Core folder.

I Think it should works with 3 or more Levels. Strrpos finds the last matching, so it is not important how many Levels you have !?

You could echo the path to see what happen

(Line 144)
Code:
// Is the model in a sub-folder? If so, parse out the filename and path.
  if (($last_slash = strrpos($model, '/')) !== FALSE)
  {
   // The path is in front of the last slash
   $path = substr($model, 0, $last_slash + 1);

   // And the model name behind it
   $model = substr($model, $last_slash + 1);
  }
...
Then the Path will be loaded(Line 194)
Quote: require_once($mod_path.'models/'.$path.$model.EXT);
#4

[eluser]csotelo[/eluser]
returns:

application/models/admin/quotes/Product_model.php
#5

[eluser]J. Pavel Espinal[/eluser]
Would it be the 'P' instead of 'p' in Product_model.php ?
#6

[eluser]Glazz[/eluser]
I have tested it and it works.

Folders:
http://dl.dropbox.com/u/19002464/teste.png


Model code for test:
Code:
<?php

class Teste_model extends CI_Model{
function teste(){
echo 'teste';
}
}

Try to use $this->load->model('your/folders/here/Product_model');
and then $this->Product_model->your_function_here();

In windows should work with product_model and Product_model it doesn't matter if it is upper case or not, but in unix systems it fails i guess.
#7

[eluser]csotelo[/eluser]
Hi, I found the problem, I'm calling model with an alias:

$this->load->model('admin/quotes/product_model', 'exec_model');


But when I remove the alias, it works. But why? I need to enter an alias, what is my mistake?
#8

[eluser]Glazz[/eluser]
[quote author="csotelo" date="1337004396"]Hi, I found the problem, I'm calling model with an alias:

$this->load->model('admin/quotes/product_model', 'exec_model');


But when I remove the alias, it works. But why? I need to enter an alias, what is my mistake?[/quote]

It works fine for me, i tested with my previous test code, and added the alias as you are using, and it worked just fine.

Are you on Windows or Linux ?
#9

[eluser]csotelo[/eluser]
Windows!
#10

[eluser]Glazz[/eluser]
It should work, try installing a fresh copy of CodeIgniter an try to load a model like you are doing know.

I can't figure it out, since it works just fine for me, with or without "alias".




Theme © iAndrew 2016 - Forum software by © MyBB