CodeIgniter Forums
Calling models from helpers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Calling models from helpers (/thread-9893.html)



Calling models from helpers - El Forum - 07-11-2008

[eluser]surfgatinho[/eluser]
Is there any way of calling functions in models from a helper?

Or alternatively, what would be the best way of having some code (for a dynamic menu) accessible by lots of different controllers?

Thanks,
Chris


Calling models from helpers - El Forum - 07-11-2008

[eluser]Seppo[/eluser]
1) if you load the helper, the functions will be available in every place

2) you can extend your controller class defining a library MY_Controller or using a hook


Calling models from helpers - El Forum - 07-11-2008

[eluser]ReGeDa[/eluser]
Code:
$CI = &get;_instance();
$CI->load->model('Something');
$CI->Something->do();



Calling models from helpers - El Forum - 07-12-2008

[eluser]surfgatinho[/eluser]
Perfect! Thanks ReGeDa.

The first line did throw an error in Hebrew (!!!) with the semi-colon in:

Parse error: syntax error, unexpected ';', expecting T_PAAMAYIM_NEKUDOTAYIM in D:\WebSites\SilverMine\system\application\helpers\cart_helper.php on line 5


Calling models from helpers - El Forum - 07-12-2008

[eluser]ReGeDa[/eluser]
it's problem of forum post. you can try it by yourself. write in form post "&get;_instance();" without ';' and you will have with ';'
Code:
&get;_instance();



Calling models from helpers - El Forum - 07-12-2008

[eluser]wiredesignz[/eluser]
Hint: Use &/amp/; minus the slashes ie:

&get_instance();

Sorry, doesn't work in code blocks. Sad