Welcome Guest, Not a member yet? Register   Sign In
Config Class, recomendation
#1

[eluser]sn4k3[/eluser]
First what you guys recommend for save/write configs for be acessed every time

does config class support write and read arrays?

also what you think is better:
standart_user.php (Store all prices, winnings for a normal user)
premium_user.php(Store all prices, winnings for a Prmium user)

OR

user_settings.php
|
|>> Store an array( array(0 => array(), 1 => array()) )

0 = Standart user
1 = Premium user



Thanks
#2

[eluser]farinspace[/eluser]
Use a database! If you cant use MySQL, use SQLite ...
#3

[eluser]sn4k3[/eluser]
is that the best way?
Renember every time a user request a page, i have to retrieve that information, so it will not overload MySQL?
#4

[eluser]farinspace[/eluser]
Thats what a database is used for ... additionally you can use sessions to store data during a users visit, this can also help alleviate the database load ...

... and as your site grows you will definitely learn/know more and you can begin looking into page/content caching strategies to reduce stress on the database (but that should come around when you have several thousands of requests per day, thats a good problem to have!)
#5

[eluser]sn4k3[/eluser]
session? its global settings, not settings per user

is just like define site name, site email, etc, etc
#6

[eluser]farinspace[/eluser]
Ah ... i've done a couple of different things in this situation:

1) I've saved site specific items in the "config.php" file itself (which really shouldn't be a problem, you'll never have thousands of config parameters anyway)

2) I've created a specific DB table "site_details" (fields: name, value), kinda like a meta data table ... and saved name value pairs in it, then I created a model to easily retrieve specific and/or all values. You could then use a base controller to distribute the values globally.

If your pages will be static in some respects, then you can use CI page caching to also improve performance. When you change values, you can manually clear the cache ...

I hope i'm on the same page now ... Smile
#7

[eluser]Twisted1919[/eluser]
Take a look here , this is what i use :
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Config extends CI_Config{

private $ci = NULL;

public function __construct()
    {
        parent::CI_Config();
    }

public function load_db_items()
    {
        if (is_null($this->ci)) { $this->ci =& get_instance(); }

    /*We already have the table, no use to verify this always .
        if (!$this->ci->db->table_exists($this->table))
        {
           $this->create_table();
        }
    */  
        $result = array();
        if( ! $result = $this->ci->cache->get(md5('general_config')))
            {
            $query = $this->ci->db->get(TBL_CONFIG);
            if($query->num_rows() > 0)
                {
                $result = $query->result();
                $this->ci->cache->write($result,md5('general_config'));
                }
            }
        if( count($result) > 0 )
            {
            foreach ($result as $row)
                {
                    $this->set_item($row->key, $row->value);
                }            
            }

    }

public function save_db_item($key, $value)
    {
        if (is_null($this->ci)) { $this->ci =& get_instance(); }

        $where = array('key' => $key);
        $found = $this->ci->db->get_where(TBL_CONFIG, $where, 1);
        $this->ci->cache->delete(md5('general_config'));
        if ($found->num_rows > 0)
        {
            return $this->ci->db->update(TBL_CONFIG, array('value' => $value), $where);
        }
        else
        {
            return $this->ci->db->insert(TBL_CONFIG, array('key' => $key, 'value' => $value));
        }
                
    }

public function remove_db_item($key)
    {
        if (is_null($this->ci)) { $this->ci =& get_instance(); }
        $this->ci->cache->delete(md5('general_config'));
        return $this->ci->db->delete(TBL_CONFIG, array('key' => $key));
    }

public function create_table()
    {
        if (is_null($this->ci)) { $this->ci =& get_instance(); }

        $this->ci->load->dbforge();

        $this->ci->dbforge->add_field("`id` int(11) NOT NULL auto_increment");
        $this->ci->dbforge->add_field("`updated` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP");
        $this->ci->dbforge->add_field("`key` varchar(255) NOT NULL");
        $this->ci->dbforge->add_field("`value` text NOT NULL");

        $this->ci->dbforge->add_key('id', TRUE);

        $this->ci->dbforge->create_table(TBL_CONFIG, TRUE);
    }    
//        
}

/* End of file MY_Config.php */
#8

[eluser]Twisted1919[/eluser]
I used Phil Sturgeon's caching library .( http://github.com/philsturgeon/codeigniter-cache )
So you query the database only once, then you get everything from cache .
Makes sense to you ?
#9

[eluser]sn4k3[/eluser]
yes, thanks to all




Theme © iAndrew 2016 - Forum software by © MyBB