Welcome Guest, Not a member yet? Register   Sign In
Can a helper load a model?
#1

[eluser]taewoo[/eluser]
Is this possible? Example?
#2

[eluser]wiredesignz[/eluser]
Have you tried? Did it work?
#3

[eluser]taewoo[/eluser]
Don't even know where to look...? Thus, no idea.
#4

[eluser]wiredesignz[/eluser]
Helpers generally assist by providing specific functions to use throughout your application, They aren't meant to be used to load CI objects.
#5

[eluser]ejangi[/eluser]
wiredesignz is right - helpers aren't "meant" to access models, but they can through the CI singleton/controller like so:
Code:
function my_helper_function()
{
    $CI =& get_instance();
    $CI->load->model('mymodel');
    $var = $CI->mymodel->whatever();
}
The get_instance() function is in the global namespace and can be called from just about anywhere, returning the base CodeIgniter object (which all the models/libraries are properties of).
#6

[eluser]wiredesignz[/eluser]
I hesitated to post something like that ucant, my reason is that the CI super object is still being used to load the model (as you said), so it may as well be done properly from the controller or even autoloaded.

It's just a matter of thinking the process through when building an application. (Do I really wan't to do this here?, is there a better way?)
#7

[eluser]taewoo[/eluser]
I just tried. No luck

Code:
A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: helpers/ajax_rating_helper.php

Line Number: 11
#8

[eluser]ejangi[/eluser]
... And what is on line 11?
#9

[eluser]taewoo[/eluser]
some function declared in the model..

PS: model was tested and it's fine..
#10

[eluser]ejangi[/eluser]
If you post the code, I can diagnose the issue, otherwise there's not much more I can do I'm afraid.




Theme © iAndrew 2016 - Forum software by © MyBB