![]() |
class include - 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: class include (/showthread.php?tid=11790) |
class include - El Forum - 09-23-2008 [eluser]xinq88[/eluser] Hello everyone, I'm new to codeigniter, but already have a pretty stupid question :down:. So the following scenario happened: I have some class which depends on an other class. So far I've written the following code: Code: /* this represents the way i use it in the present */ Code: class Uur extends Controller { I don't think this is the 'codeigniter way' to include a class, because in this situation I can't seem to use the database helper etc. Also the constructor of the class Uur is not called when the following method is called: $this->uur = new Uur(); The output when I don't load the database helper in a specific function (like 'toevoegen') i get the following error while I have the database autoloaded: Code: Call to a member function get() on a non-object I hope my poor English is understandable. With kind regards, Nick (PS: I did google..) class include - El Forum - 09-24-2008 [eluser]xinq88[/eluser] * little bump * class include - El Forum - 09-24-2008 [eluser]missionsix[/eluser] Code: function index() if this is your constructor, then you've named it wrong. Constructors start with either the class name in php 4+ or __construct() in php5+. Code: function Uur() { // php 4 If you want to reference the CI core and its inheritance, you need to use this function: Code: $ci =& get_instance(); It might be easier to put implement this class as either a model, or a library, depending on what it does. Generally if its interacting with database stuff then you have yourself a model. class include - El Forum - 09-24-2008 [eluser]xinq88[/eluser] Great, the library functionality does pretty much what I need. Could've known this by reading the manual one more time ![]() Still one more problem. As I said, I loaded the database library automatic (in the autoload.php). When I use a library for my Uur class it doesn't know this library. There's the problem because when I try to load it in the constructor of the class it gives me an error. Code: function Uur() results in: Code: Fatal error: Call to a member function database() on a non-object When I don't load it at all, the function "return $this->db->get('uren');" returns the following message: Code: Call to a member function get() on a non-object in I have no idea how to do this on the CI way, maybe you can point me in the right direction. Thank you for your help! edit: Code: function __construct() this works for me but is there a way of doing this for all libraries at the same time so I don't have to implement that in every library? Something like what an autoload is for a constructor? class include - El Forum - 10-03-2008 [eluser]xinq88[/eluser] Here I am again with a question. Here is the scenario: I want to create a Controller called MY_Controller extending Controller, so far no problem for me. But then I want to extend the MY_Controller by 'AnotherController' so. This is not all, at last I want to extend the 'AnotherController' controller. Code: class AnotherController extends MY_Controller { But this: AnotherController2 extends AnotherController doesn't work, the application can't find the AnotherController class (It does find the MY_Controller class though). Or maybe I put the files in the wrong dir? I have them in application/controller/ class include - El Forum - 10-05-2008 [eluser]xinq88[/eluser] Found the solution, I didn't knew I had to load the controller manually. The following code worked for me: Code: require(APPPATH.'controllers/controllerName'.EXT); |