Welcome Guest, Not a member yet? Register   Sign In
Help me understand the basics
#1

[eluser]greg.thompson[/eluser]
Hi guys, been fooling around with CI for a few days now, built out a nice login form with HASH/SALT security, validation etc. but there's one basic I can't quite seem to grasp and its "$this". So basically what I'm confused about is when I have some controller call a specific model then load a view, what all is accesible by the view and what is stored in $this? for example, I the user login, it validates, stores their basic info to the userdata like name and roles. Now in the view, what can I trigger with this? How come I call $this->session and it works? I always thought $this was only referencing the current object/class that you're currently in. But $this is a variable, and not 'this'. Do I even make sense?
#2

[eluser]CroNiX[/eluser]
The best way to understand CI, or any other application really, is to start with index.php and trace the code. That will be more insightful than any explanation. When you get to /system/CodeIgniter.php, it will become more clear how the CI super object gets created and extended.

You can also do a var_dump($this) to see what's available at any given time, but it won't help you understand how things are working.
#3

[eluser]greg.thompson[/eluser]
Thanks for the response. I did the var_dump and wow are there a lot of items. I guess my major confusion is that generally to pass variables through all these functions you need to explicitly do it, With this it seems that everything is held globally in $this, I'm sure controlled by the framework.
#4

[eluser]CroNiX[/eluser]
In short, $this = CI. All core classes are instantiated and merged into the CI super object, and then any models/helpers/libraries, etc that you 'load'. It's kind of a singleton.




Theme © iAndrew 2016 - Forum software by © MyBB