Welcome Guest, Not a member yet? Register   Sign In
how can i preset a variable value and get access to it in CI
#1

[eluser]searain[/eluser]
Code:
$profile_field_array = array(
        "about_me",
        "activities",
        "affiliations",
        "birthday",
        "books",
        "current_location",
        "education_history",
        "first_name",
        "hometown_location",
        "hs_info",
        "interests",
        "is_app_user",
        "last_name",
        "meeting_for",
        "meeting_sex",
        "movies",
        "music",
        "name",
        "notes_count",
        "pic",
        "pic_big",
        "pic_small",
        "political",
        "profile_update_time",
        "quotes",
        "relationship_status",
        "religion",
        "sex",
        "significant_other_id",
        "status",
        "timezone",
        "tv",
        "wall_count",
        "work_history");

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?
#2

[eluser]jedd[/eluser]
I'm not sure I understand your problem.

But, having said that, have you looked at [url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]the session class[/url] and found it insufficient for your requirements?

Beyond that .. perhaps some attributes of MY_Controller?
#3

[eluser]devbro[/eluser]
1. create a helper
2. create a function that returns your values
3. call something like
$profile_field_array = profile_field_array_values();
#4

[eluser]searain[/eluser]
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.
#5

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

[eluser]obiron2[/eluser]
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.

Obiron




Theme © iAndrew 2016 - Forum software by © MyBB