![]() |
Difference in CI session - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Difference in CI session (/showthread.php?tid=53401) Pages:
1
2
|
Difference in CI session - El Forum - 07-22-2012 [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 Difference in CI session - El Forum - 07-23-2012 [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. Difference in CI session - El Forum - 07-23-2012 [eluser]global_erp_solution[/eluser] so, they're both super objects? I'm confused Difference in CI session - El Forum - 07-23-2012 [eluser]Sanjay Sarvaiya[/eluser] yes Difference in CI session - El Forum - 07-23-2012 [eluser]global_erp_solution[/eluser] so, no difference whatsoever between the two? both are interchangeable? completely identical with no different effect? Difference in CI session - El Forum - 07-23-2012 [eluser]LuckyFella73[/eluser] There is a difference! See User Guide for detailed information: http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html Section: "Utilizing CodeIgniter Resources within Your Library" Difference in CI session - El Forum - 07-23-2012 [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. Difference in CI session - El Forum - 07-23-2012 [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. Difference in CI session - El Forum - 07-30-2012 [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 Difference in CI session - El Forum - 07-30-2012 [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. |