object oriented class |
[eluser]dadamssg[/eluser]
I only know object oriented programming because i learned from using codeigniter. So i have little understanding of it outside of codeigniter. Was wondering how you assign a class into a variable for instance Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); And then when i reference it in my controller like this Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I also understand(i think) you can load all of the functions in the class when you put "new" in front of referencing the class. You load the class as an object and then can reference the different functions with "->". But this code doesn't work. I think because i don't know how to load the class as an object. I'm referencing the "numbers" function in the "numbersclass" when i should somehow be referencing the whole thing. I don't know how to do that though. i have just been using on of functions in the class to call the other functions and then putting all of those returns into an array and then returning that single array. It'd be nice if i could reference the functions like i have in the above code. Can someone point me in the right direction?
[eluser]ted wong[/eluser]
You should do it in the library first, then, you can start load your library, in this case, your Numbersclass. Don't expect the Codeigniter do this magic for you. Take a look: http://ellislab.com/codeigniter/user-gui...aries.html
[eluser]Rolly1971[/eluser]
the way your doing it is not needed. for example Code: public function index() is better written like: Code: public function index() because the way CI works is when it loads a class using: $this->load->library('classname') a reference object is automatically created with the same name as the class. the way you are coding it your creating a reference to a class from a reference to a class which is a bit in-efficient. |
Welcome Guest, Not a member yet? Register Sign In |