Welcome Guest, Not a member yet? Register   Sign In
Can't access global variable from a helper?
#11

[eluser]stormbytes[/eluser]
Point taken - Smile

Sorry about the confusion!
#12

[eluser]InsiteFX[/eluser]
If this is for a navigational menu why not just use a database?

InsiteFX
#13

[eluser]stormbytes[/eluser]
To populate the nav? Not sure what you mean..

But my function doesn't actually populate anything, it takes arguments and then determines how to render the nav-items based on the current url (static text or links)
#14

[eluser]kaejiavo[/eluser]
[quote author="stormbytes" date="1288148527"]Marco,

I just tried loading the config file using $CI->load->config() prior to accessing the index, and it worked! I'm glad you posted the tip as this half-solves my problem, though my original question still stands. Why can't the helper access pre-loaded variables? ($this->load->vars($var_name)). They are certainly accessible from the View, and the helper function is being called from the View. Weird..

A follow up question -

Do you know if it's possible to pick up the value of default controller from Routes.php programmatically somehow?

Cheers![/quote]

Daniel,
if you read the user_guide chapter Helpers, you will learn that helpers
Quote:Unlike most other systems in CodeIgniter, Helpers are not written in an Object Oriented format. They are simple, procedural functions. Each helper function performs one specific task, with no dependence on other functions.
As a function doesn't know of your object context, this should be the answer to your question.
If you need a ver in a function you have to submit it as a parameter, as you certainly know.
myfunction($param1, $param2, $param3)

So when you have received the vars from your config file in your controller or view, simply change your helper function so that it accepts them as params and there you go.

Marco




Theme © iAndrew 2016 - Forum software by © MyBB