eakgul
eakgul

Reputation: 3698

Codeigniter controllers var

I got a conroller like:

class listItems extends CI_Controller{
    private $num;

    public class __construct(){
        parent::__construct();
        $this->num=10;
    }

    public class index(){
        echo $this->num;
    }
}

when i do this i got nothing. why?

Upvotes: 0

Views: 40

Answers (1)

Robin Castlin
Robin Castlin

Reputation: 10996

Two different classes. Needs to be under the same, so use function instead.

class listItems extends CI_Controller {

    private $num;

    public function __construct() {
        parent::__construct();
        $this->num=10;
    }

    public function index() {
        echo $this->num;
    }

}

Upvotes: 2

Related Questions