Messing with OOP in Codeigniter - 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: Messing with OOP in Codeigniter (/showthread.php?tid=57041) |
Messing with OOP in Codeigniter - El Forum - 02-10-2013 [eluser]fran-quero[/eluser] Hello I have been some time working with CI (awesome framework!), and now I'm reading about OOP in order to create my own libraries. Theory is almost clear, but practice is another song I'm creating a test library, but I don't know how to an object instance after sending a form or moving between a controller methods. I tried both with the same result. Please, take a look to my code and feel free to give me all advices and corrections as necessary: My Class Code: class FqGallery Controller: Code: class Gallery extends CI_Controller The view Code: echo $confirmation_message; I can bypass this issue using session flashdata, but I'd like to know the correct way to work with object instances. Thanks in advance for your help and advices! Messing with OOP in Codeigniter - El Forum - 02-10-2013 [eluser]rjsmith[/eluser] First, since you want to use CI resources in your library, you have to grab a reference to CI. For example, here's what I would do: Code: class FQGallery{ I would also return 'this' in my methods in case I wanted methods to be chainable. Next, in the controller: Code: class Gallery extends CI_Controller{ Messing with OOP in Codeigniter - El Forum - 02-11-2013 [eluser]Aken[/eluser] [quote author="rjsmith" date="1360525099"]First, since you want to use CI resources in your library, you have to grab a reference to CI.[/quote] They did that already through the __get() method. Unless you need to create multiple instances of an object, your library is already instantiated once when you load it. Code: $this->load->libary('fqgallery'); Messing with OOP in Codeigniter - El Forum - 02-11-2013 [eluser]rjsmith[/eluser] I didn't know __get() would work in the constructor |