Difference in CI session |
[eluser]global_erp_solution[/eluser]
I've encountered code Code: $CI =& get_instance(); and this Code: $this->session->set_userdata('logged',$user); what's the different effect between the two? when to use which? thanks
[eluser]Sanjay Sarvaiya[/eluser]
as per my knowledge you know CI is super object and we can get it using this syntax Code: $CI =& get_instance(); and this syntax Code: $this->session->set_userdata('logged',$user); $this is a super object of CI. my presentation is not much enough to explain whole things.
[eluser]global_erp_solution[/eluser]
so, they're both super objects? I'm confused
[eluser]global_erp_solution[/eluser]
so, no difference whatsoever between the two? both are interchangeable? completely identical with no different effect?
[eluser]LuckyFella73[/eluser]
There is a difference! See User Guide for detailed information: http://ellislab.com/codeigniter/user-gui...aries.html Section: "Utilizing CodeIgniter Resources within Your Library"
[eluser]Aken[/eluser]
$this->session is used in controllers and models. get_instance() is used everywhere else. Read more about PHP OOP and property scope to learn more about $this.
[eluser]skunkbad[/eluser]
Aken is right. CodeIgniter makes all loaded models and libraries available to the controller, which is why they are available using $this. $this refers to the controller instance, so when you are inside a controller, you are effectively accessing a property (sometimes called a member) that has been created for you by CI. You don't see it often in CI, but in many OOP implementations you will see "::". This is a scope resolution operator, and is usually used to call a static method, instead of "->", which is only used for accessing methods that are not static.
[eluser]global_erp_solution[/eluser]
so, what's the different effect of using those two? and what does this have to do with LuckyFella73's creating libraries? any explanation? thanks
[eluser]InsiteFX[/eluser]
Because with out the CI super object you cannot call the database or other libraries in a libaray Create a library and try calling $this->session or $this->db You will get an error. |
Welcome Guest, Not a member yet? Register Sign In |