how can i preset a variable value and get access to it in CI

$profile_field_array = array(

In traditional php, I can just save this in a php file and include it when I need it. In CI everything libray, helper, plugin etc, either class or function, not just for assign values to a variable (an array in this case).

how could I do it right in CI? or just do it like in traditional php, save it in php file and include it when I need it?

I'm not sure I understand your problem.

But, having said that, have you looked at [url=""]the session class[/url] and found it insufficient for your requirements?

Beyond that .. perhaps some attributes of MY_Controller?

1. create a helper
2. create a function that returns your values
3. call something like
$profile_field_array = profile_field_array_values();

thanks devbro.

I got it.

I was using put these files in a includes folder and use require_once to call it. But just feel like it is a "traditional php programming" not CI.

I have been thinking about use helper function and return the value, just not sure if it is CI way.

Thanks again.

[eluser]Colin Williams[/eluser]
Why not add it to config?

I'd be tempted to create a model as they are 'properties' of the user.

Create a method in the model to return the array and call if from the controller.

Later on, when your project gets more complex, you can update the model to retrieve the properties from a database and the whole thing will still work.

that is the beauty of MVC; the controller doesn't care how the model prepares the data, as long as it gets back the expected result.

I use this technique a lot for menu functions - while the list is fixed/limited and in development I return a hard coded array. when the site goes live and menus need to be derived from user profiles then the array is built dynamically in the model.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.