CodeIgniter Forums

Full Version: Calling models from helpers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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

El Forum

[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

El Forum

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

El Forum

[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

El Forum

[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();

El Forum

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

&get_instance();

Sorry, doesn't work in code blocks. Sad