Welcome Guest, Not a member yet? Register   Sign In
Can't define variable/attributes inside Controller
#1

[eluser]peterbz[/eluser]
I can't seem to define attributes (variables) inside my Controller

Code:
class UsedCars extends Controller {

    private $tabSelected = "usedcars";
    
    function __construct()
    {
        parent::Controller();    
    }
    
    function index(){
        $common = array();
        $common['tabSelected'] = $tabSelected;
        $common['view'] = "usedCars";
        
        $data = array();
        $data['common'] = $common;
        
        $this->load->vars($data);
        $this->load->view("layout");
    }
    
}

When I run this, it prompts me that $tabSelected is not defined.
#2

[eluser]peterbz[/eluser]
Problem solved. I have to put $this->tabSelected instead of $tabSelected

I'm new to PHP so didn't know you have to write it like that. In other languages, leaving out the this. is quite trivial




Theme © iAndrew 2016 - Forum software by © MyBB