Fatal error: Call to undefined method |
[eluser]Perkin5[/eluser]
I'm getting this response after calling a very simple method from the controller like this: Code: function fetchcode(){ The model method is: Code: function get_code(){ I've got the model method primed to 'print_r die' when it is called but codeigniter tells me it's undefined. I know the Model is loaded as I'm successfully calling a number of other methods from the same model. Any idea what's wrong?
[eluser]boltsabre[/eluser]
Reference: http://ellislab.com/codeigniter/user-gui...tml#select http://ellislab.com/codeigniter/user-gui...sults.html You have to run ->result() inside a loop.
[eluser]aquary[/eluser]
boltsabre, errr.... no, in the userguide is just an example that you could do it that way, but it doesn't mean you have to. Perkin5's ways is already good. Perkin5, you saw only that error ? there should be something more about which method is undefined. Are you sure it's the print_r() line? or was it get_code() that was undefined? In that case, show us the code above the get_code(). Sometime an extra "}" would make a lot of confusing errors.
[eluser]Perkin5[/eluser]
The full error line is: Fatal error: Call to undefined method Admin_model::get_code() in C:\wamp\www\historystoreNew\application\controllers\admin2012.php on line 119 line 119 is the third line of fetchcode ie where the call to the model method occurs. I've simplified get_code in the model to this: Code: function get_code($pricecat){ The controller method fetchcode is: Code: function fetchcode(){ price_cat is the name of the db table I'm trying to access. The model is admin_model.php and I loaded it in the controller constructor like this: Code: $this->load->model('Admin_model'); and I know that's OK because other controller methods are accessing other model methods perfectly satisfactorily. I almost convinced myself that get_code was a reserved word in codeigniter but it isn't. Another thing I've tried is to copy the get_code method into the controller and access from there - modifying fetchcode obviously - in which case it works fine The syntax of fetchcode is identical to other successful methods - I can't understand what's going wrong.
[eluser]aquary[/eluser]
Check every lines above the get_code(). You might have an extra "}" somewhere before, especially... 1 line above. If there is other function below get_code() (or make one if there aren't), try using them also. If you got the same error, it must be about the "}" I spoke about.
[eluser]Perkin5[/eluser]
Aaaaah! Thank you Aquary! You said that a } out of place could cause problems and that was it. I had two out of place and they were so positioned that the code editor didn't throw a warning. But because of what you said, I checked them all super-carefully and found the two errors. Now corrected and all working normally. Such a small error and so much time to find it!!! |
Welcome Guest, Not a member yet? Register Sign In |