I read this question but it can't help me a lot...
Using Ion_auth
library I noted that the data to a view are passed by $this->data[]
and not simple by $data
.
Why? Where is the difference or the vantage to do this?
I read this question but it can't help me a lot...
Using Ion_auth
library I noted that the data to a view are passed by $this->data[]
and not simple by $data
.
Why? Where is the difference or the vantage to do this?
Using $this->data means you can make use of OOP inheritance of a parent controller. The parent controller such as MY_controller can set some initial data which becomes available in all controllers that extend it.
There's an example here: http://avenir.ro/codeigniter-tutorials/creating-working-with-my_controller-codeigniter/
$this->data[]
That means you have to define the $data
member in your class,
And $this
reference the current object, simply the current class
When you define
Class Oop
{
private $data = array();
function test()
{
$this->data['title'] = 'Home';
echo $this->data['title']; //access like this
}
}
In codeigniter $data
is an array
In controller you can $data['title'] = 'Home';
Then in view you can access it like $title;
Please reference this oop