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

#1
[eluser]itibook[/eluser]
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

Luca

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

#3
[eluser]itibook[/eluser]
Thanks. It looks indeed like the right match, I will search better on that side. Thanks again

#4
[eluser]itibook[/eluser]
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...

http://www.echovsprint.com/2009/04/role-...ing-hooks/
http://codeigniterandjquery.blogspot.com...in-ci.html

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...

ciao

Luca

#5
[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:
Code:
CREATE TABLE `preferences` (
`name` text,
`value` text
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
next add following function in some of your models:
Code:
function get_pref($name){
  $q = $this->db->select('value')->where('name', $name)->get('preferences');
  if($q->num_rows()>0)
  {
    $row = $q->row_array();
  }
  return $row['value'];
}
and after that you can use it in your view file, like this:
Code:
<title><?=$this->m_common->get_pref('site_name')?></title>
Or you can grab all preferences at once and put them in array.

#6
[eluser]itibook[/eluser]
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.

ciao

Luca


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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