0
class MY_Controller extends CI_Controller
{

    public $username;

    function __construct()
    {
        parent::__construct();
        $this->username = "User";
    }
}

class Post extends MY_Controller
{

    public function index()
    {        
        $data = array(
            'name'=>'CodeIgniter',
            'username' => $username
        );

        $this->template->load('post/index', $data);
    }
}

I don't access to $username in Post class, how to fix this problem?

2
  • 3
    So you have MY_Controller with public username property, that extends CI_Controller, and Post class that extends MY_Controller, and you want to access $username? did i understand corectly? then try $this->username Commented Mar 13, 2017 at 20:17
  • You should post this as an answer @DanIonescu Commented Mar 13, 2017 at 20:37

1 Answer 1

1

If you have MY_Controller with public username property, that extends CI_Controller, and Post class that extends MY_Controller then to access username property from inside Post class use:

$this->username
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.