Welcome Guest, Not a member yet? Register   Sign In
Variable Accessible In View, But Not Within View's Function?
#1

[eluser]Walter Coots[/eluser]
I'm stumped. I'm defining a function in my view which is trying to access a variable passed from the controller. The function itself returns an error as if the variable isn't defined. However if I print_r() the variable outside of that function, it shows up as expected.

In my controller:

Code:
function constructAndShowToolbar()
    {
        $toolbarLinks['new'] = Array();
        $toolbarLinks['edit'] = Array();
        $toolbarLinks['system'] = Array();
        $toolbarLinks['groupings'] = $this->TableOptions_model->getTableGroups();

        /* [...] Code to populate the empty arrays */

        $this->load->view('skins/admin/toolbar',$toolbarLinks);
    }

Then in my view:

Code:
function createTopLevelMenu($arr,$title='UNTITLED')
    {
        if($groupings != NULL) /* Returns, "PHP Error- undefined variable: "groupings"  */
        {
            print_r($groupings);
        }
    }
    
    print_r($groupings); /* Prints the array in its entirety */

    createTopLevelMenu($new,'New');
    createTopLevelMenu($edit,'Edit');
    createTopLevelMenu($system,'System');
}


Messages In This Thread
Variable Accessible In View, But Not Within View's Function? - by El Forum - 12-05-2010, 12:36 PM



Theme © iAndrew 2016 - Forum software by © MyBB