[Question - Solved] Adding/editing site variables from controllers

edited June 2011 in Feature Requests
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

  • edited 8:43PM
    So you are wanting a page counter like variable that is also editable in the admin?
  • edited June 2011
    I need a variable that I can access and edit and save for later use in any page of the website.
  • edited 8:43PM
    That sounds like something that a site variable should be able to do for you. If you need to update the value of a site variable outside of the admin, then you could load and use the sitevariables_model to do updates (in a view or controller):
    // 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.
  • edited 8:43PM
    Thanks for the help and the fast reply. This works just fine.
    As a small note, if you want to use the above code in a Model you should add this before it $CI = &get_instance();
Sign In or Register to comment.