Welcome Guest, Not a member yet? Register   Sign In
Global Variable
#1

[eluser]Unknown[/eluser]
Hi Guyz!

I have a little problem with global variables.

I have some page on my site, which presents portfolio. It shows 6 small thumbs and when you click on particular thumb, it shows full page along with some additional info regarding that site. It's pretty straightforward. So, in my model, I've used this:

Code:
function get_entries_by_limit($limit_from, $limit_num)
    {
        $query = $this->db->get('sites', $limit_num, $limit_from);
        return $query->result();
    }

Limit number is 6, always, but, $limit_from is a variable which needs to be global. At portfolio index, I have a call get_entries_by_limit(0, 6) and it's fine, but now I need two things: 1) where to define global variable $limit_frpm; 2) when I click previous/next buttons to decrement/increment $limit_from. After the increment/decrement, I want to call get_entries_by_limit($limit_from, 6);.

Sorry if similar question was already posted by someone. I've used the search engine, but couldn't find it.
#2

[eluser]jedd[/eluser]
Hi djalfirevic and welcome to the CI forums.

If you read through the [url="/wiki/FAQ"]FAQ[/url], you'll find a few possible hints, though nothing specific to this one problem. You may want to look at extending [url="/wiki/MY_Controller"]MY_Controller[/url] - mostly as a likely place to put the functions that will do the changing of this 'global variable'. But I'm getting slightly ahead of myself.

You should probably investigate the [url="/user_guide/libraries/sessions.html"]Session Class[/url], particularly if you're doing any kind of user management - as it means you can set this (from the database, or one of your new application's config files) at login - and then modify it, using the Session Class functions, in response to the user doing the click-thing.

I usually have a function that will get/set the relevant bit of session data, but it's probably just as easy and neat to pull those bits of data in using $this->session->... calls.




Theme © iAndrew 2016 - Forum software by © MyBB