CodeIgniter Forums
Accessing methods from more than one class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: Accessing methods from more than one class (/thread-76450.html)



Accessing methods from more than one class - fraggley - 05-14-2020

Hi all,

Hope you can help guide me here:

I am building as app and have different controllers per object. One Controller I have is, let's say, Car, and then I have separate controllers for enginewheelschassisGPS. I know that for my car to access the wheels methods i can use:

PHP Code:
class Car extends Wheels 

But then how can my Car class also access the methods in the Engine, Chassis and GPS classes.
As I understand it, I can't extend to multiple classes. So do I just need to replicate the relevant Wheels methods in Car. It seems inefficient.
Thanks


RE: Accessing methods from more than one class - jreklund - 05-14-2020

No, those types of files should be libraries. You create them without extending the main Controller, just an empty class. And you load it in your controller car.

PHP Code:
$wheels = new \App\Libraries\Wheels(); 



RE: Accessing methods from more than one class - InsiteFX - 05-15-2020

@jreklund is correct you should be putting those methods in a libraries