• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Store site configuration on database

Hi all,

pretty new here, so feel free to some links if you think I missed something. Just to be clear I spent a couple of hours on the forum and google, but couldn't find an answer, so that's why I am posting...

I would like to be able to set some basic configuration fields (e.g. website name, website email, etc) in a database table and make sure that they get loaded at each page so that I can re-user those value in each model/view.

The end game is to have those configuration settings editable in the admin panel. It's not rocket science, I am sure, but I can't seem to grasp where and how I should do that.

thanks in advance


[eluser]GSV Sleeper Service[/eluser]
sounds like a perfect use for hooks. http://ellislab.com/codeigniter/user-gui...hooks.html

Thanks. It looks indeed like the right match, I will search better on that side. Thanks again

just posting here in case anyone else has the same problem and looks for a solution:

I found this two links that gave me the direction...


I settled for having a hook that retrieves the settings from my database and defines them as constants so that I can call each setting from any MVC

again thanks GSV Sleeper Service for giving me the right direction...



[eluser]Dark Preacher[/eluser]
I'll try to suggest my own solution, as I've done before (and doing now).
First create table "preferences" in your database:
CREATE TABLE `preferences` (
`name` text,
`value` text
next add following function in some of your models:
function get_pref($name){
  $q = $this->db->select('value')->where('name', $name)->get('preferences');
    $row = $q->row_array();
  return $row['value'];
and after that you can use it in your view file, like this:
Or you can grab all preferences at once and put them in array.

Hi Dark Preacher,

I am basically doing the same, but with the hooks solution suggested it means that the preferences are always available as they are loaded before anything else, basically they are like config variables.

anyway, thanks for the suggestion, hadn't thought of it, so it might come in handy for other cases.



Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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