[Question - Solved] Adding/editing site variables from controllers
Hi, I have a question about Site variables. Is there an easier/better way to add or edit Site variables other than Querying the DB manually or using the admin dashboard?
The reason I'm asking is this. I need a "dynamic" site variable that I can easily edit whenever an even occurs, when page is viewed for example to count how many times it's been viewed.
Comments
// in a view example $CI->load->module_model(FUEL_FOLDER, 'sitevariables_model'); $new_value = array('value' => 'my_new_value'); $where = array('name' => 'counter'); $CI->sitevariables_model->update($new_value, $where);
As a side note, and something you may already know, site variables are automatically loaded for pages controlled by the admin, or pages using the opt-in controller method (no controller, just a view file). So for example, if you have a site variable named 'counter', you can merge in that value by simply calling $counter in your view file or {$counter} in your page controlled by the admin.
As a small note, if you want to use the above code in a Model you should add this before it
$CI = &get_instance();