Model working in one controller, but not in another. |
[eluser]mdrisser[/eluser]
Hi all. I have a rather perplexing problem. I have a Model with to functions each does a select * on a different table. I'm using these values to populate two select lists. In one controller everything works as expected, in a second controller, using the exact same code, it doesn't work. That is, it doesn't return anything. Here's the code: In both controllers: Code: $this->load->model('Search_model', 'Search'); And the Model is: Code: class Search_model extends Model { Function in 1st controller, which works fine: Code: function search() { Function in 2nd Controller, which doesn't work: Code: function process_form() { Quote:A PHP Error was encountered I'm sure I must be doing something wrong, but I can't for the life of me figure out what it is.
[eluser]jcopling[/eluser]
I can't really speak to why this particular bit of code will work in one place but not in another. But my suggestion would be to try a print_r() on the variable $this->types and $this->cities inside the view. Personally, extending CI to contain your data with: Code: $this->data['types'] = $this->Search->get_types(); Code: $data['types'] = $this->Search->get_types(); Hope this helps.
[eluser]mdrisser[/eluser]
Doing a print_r on $this->types gave me the same type of message. I'm not seeing much difference between your code and mine, aside from my $data being a class variable and yours being local to the function. Mine is a class variable, because in the constructor I'm setting a few other parts of the array. I've set the log_threshold to 4 and noticed in the logs that in the Controller that isn't having any problems, the Model is being initialized, but in the Controller that is broken, the Model is not being initialized. I've tried moving $this->load->model('Search_model', 'Search'); to various places within the broken Controller in the vain hope that maybe it just needed to be called in a different place, but kept coming up with the same result.
[eluser]mdrisser[/eluser]
D'OH! I found the problem, I was trying to load the Model in a function that I wasn't calling at that point. I was calling: http://localhost/myapp/index/php/addplace and the Model was being loaded in the process_form function, which means it wasn't being loaded until I called http://localhost/myapp/index.php/add_place/process_form |
Welcome Guest, Not a member yet? Register Sign In |