Welcome Guest, Not a member yet? Register   Sign In
Defining variables to be used throughout a controller
#1

[eluser]Fielder[/eluser]
I have a variable say $var that is used throughout the entire controller. How do I define it at the beginning of the controller so I can call it anywhere in any function in the controller?
Is this correct?

Code:
<?php

class ContractStore_Form extends Controller
{
    
    function ContractStore_Form()
    {
        parent::Controller();

        $this->load->library('DX_Auth');
        $this->load->library('RTUI_App');
        $this->load->library('RTUI_Form_Elements');
        $this->load->library('XajaxGrid');
        
        $this->dx_auth->check_uri_permissions();
        
        $this->load->model('Stores', 'store', TRUE);
        $this->load->model('Contracts','contract', TRUE);
        
        // Initialize
        $this->_init();
        
    }

    function _init()
    {
        $this->var = 2;
    }
    function somefunc($storename_name)
    {
        $newvalue = $this->var + 4;

        return $newvalue;
    }
    function anotherfunc($blah)
    {
        $newvalue = $this->var + 8;

        return $newvalue;
    }
.
.
.

And second to that, what if I wanted a function to perform a task to create a variable, but I didn't want to return it. I just wanted the results of the function to be available anywhere else in the controller.

Code:
function open()
{
$this->rowopen = "<tr><td>";
}

function close()
{
$this->rowclose = "</td></tr>";
}

function render()
{
$final = $this->rowopen . $this->rowclose;
}

I've tried just this and it doesn't work... I suspect something having to do with how the controller is setup.?
Thanks.


Messages In This Thread
Defining variables to be used throughout a controller - by El Forum - 07-01-2009, 11:04 PM
Defining variables to be used throughout a controller - by El Forum - 07-01-2009, 11:09 PM
Defining variables to be used throughout a controller - by El Forum - 07-01-2009, 11:18 PM
Defining variables to be used throughout a controller - by El Forum - 07-01-2009, 11:31 PM
Defining variables to be used throughout a controller - by El Forum - 07-01-2009, 11:49 PM
Defining variables to be used throughout a controller - by El Forum - 07-01-2009, 11:57 PM
Defining variables to be used throughout a controller - by El Forum - 07-02-2009, 12:35 AM



Theme © iAndrew 2016 - Forum software by © MyBB