Welcome Guest, Not a member yet? Register   Sign In
Saving application related settings
#1

[eluser]ilSignorCarlo[/eluser]
Hi,
in an application I'm developing I need to let the user to choose and save different settings, options and behaviours.

For example, in the public section of the site there should be a navigation menu populated with tags. These tags should be set from the admin panel. Which would be the best way to save informations for this panel? Since I have a table "Tags" in the database, I think that the simplest solution would be to add a column "menu" with a boolean value so that if it is "true" the tag appears in the menu. I don't really like this solution, because the tags can be a lot, while in the menu there should be just 4 or 5, so on every page it should check the whole table.

Another solution would be to use a configuration file, but I'm not sure if this may be a good practice. What do you think? How should that work? Is it possibile to use the CodeIgniter application config file or would it be better to create another one more specific for these kind of settings?

I hope the question is clear enough,
thanks
#2

[eluser]Tim Reynolds[/eluser]
If your going to be frequently changing these values then the database is the way to go. This allows you to alter the settings from the admin panel.

Settings that are relatively static can go into config files. For more inforamtion on using config files check out,

http://ellislab.com/codeigniter/user-gui...onfig.html
#3

[eluser]ilSignorCarlo[/eluser]
[quote author="Tim Reynolds" date="1262538635"]If your going to be frequently changing these values then the database is the way to go. This allows you to alter the settings from the admin panel. [/quote]

Yes, but I'm not sure what would be better. I'm not going to manage the site, so I don't know if they are going to change these settings so often. Anyway, these tags are intended to work as the categories in a Wordpress blog. I think they won't change so often. Another setting to choose may be a theme to change the appearance.

I think the config file is more appropriate, isn't it?

Quote:Settings that are relatively static can go into config files. For more inforamtion on using config files check out,

http://ellislab.com/codeigniter/user-gui...onfig.html

Thanks for this.
#4

[eluser]Tim Reynolds[/eluser]
It is hard to say. I think a lot of it comes down to personal preference i normal try to keep as much as possible dynamic. This can often add additional work but makes later maintenance easier.
#5

[eluser]ilSignorCarlo[/eluser]
I'm trying to set the config item for this menu in this way:

Code:
$menu_tags = explode(" ", $_POST['menu_tags']);
print_r($menu_tags);
$this->config->set_item('menu_tags', $menu_tags);

But nothing happens. What am I doing wrong?
#6

[eluser]Tim Reynolds[/eluser]
Am struggling to see what you are trying to do. But you need to use,

$this->input->post('menu_tags');

instead of,

$_POST['menu_tags']

as outlined in the user guide,

http://ellislab.com/codeigniter/user-gui...input.html
#7

[eluser]ilSignorCarlo[/eluser]
[quote author="Tim Reynolds" date="1262548890"]Am struggling to see what you are trying to do. But you need to use,

$this->input->post('menu_tags');

instead of,

$_POST['menu_tags'][/quote]

Well, ok, but that is not the problem.

In the view I have a text field where I write the tags. I submit them and in the controller I explode them to create the array $menu_tags. Now I try to set the item in the config file, but it doesn't work.
#8

[eluser]ilSignorCarlo[/eluser]
I figured out what is wrong, I think.

In the config directory I created this file: my_config.php. Inside I have this: $config['menu_tags'] = array();

I was trying to change this value from the controller, using:

$this->config->set_item('item_name', 'item_value');

It seems that this is not the way it is supposed to work. So, how should I do it? How can I set options from an admin panel?
#9

[eluser]Tim Reynolds[/eluser]
this->config->set_item is only designed to dynamically set a config option. To write to a file you will need to use the file helper.

The config class only provides a means to retrieve configuration preferences.
#10

[eluser]ilSignorCarlo[/eluser]
[quote author="Tim Reynolds" date="1262554709"]this->config->set_item is only designed to dynamically set a config option. To write to a file you will need to use the file helper.

The config class only provides a means to retrieve configuration preferences.[/quote]

Yes, I see. So I'd need to parse the config file to properly write in it.




Theme © iAndrew 2016 - Forum software by © MyBB