Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在CodeIgniter中扩展多个类?_Php_Codeigniter - Fatal编程技术网

Php 如何在CodeIgniter中扩展多个类?

Php 如何在CodeIgniter中扩展多个类?,php,codeigniter,Php,Codeigniter,如何像这样扩展多个类: class Backend_api extends CI_Controller, Appointments { do stuff... } PHP不支持多重继承如前所述,PHP不支持多重继承。 但是由于PHP5.4,你可以使用特质并在课堂上使用它们。关于traits的更多信息如上所述,php中不允许多重继承,但是如果您需要访问Appoints类中的函数,为什么不在该类中创建它的实例并在该实例上调用该函数呢 $ins = new Appointments(

如何像这样扩展多个类:

class Backend_api extends CI_Controller, Appointments
{
        do stuff...
}

PHP不支持多重继承

如前所述,PHP不支持多重继承。
但是由于PHP5.4,你可以使用特质并在课堂上使用它们。关于traits的更多信息如上所述,php中不允许多重继承,但是如果您需要访问Appoints类中的函数,为什么不在该类中创建它的实例并在该实例上调用该函数呢

$ins = new Appointments();
$result = $ins->someFunction();

在约会类中,您可以像这样从CI_控制器进行扩展

class Appointments extends CI_Controller
{
        //stuff...
}
现在您可以从约会扩展,因为它已经从CI_控制器扩展

class Backend_api extends Appointments
{
        //do stuff...
}

嗯,这对我来说是个问题,因为我需要使用CI_Controller的一些方法,还需要使用Backend_api类的appoints类中可用的函数。尝试放弃所需的objectshow我可以实现吗?例如,在构造函数中:
$this->object1=new Class1
$this->object2=newclass2,类似于这样。并在对象的方法中使用此对象<代码>$this->object1->method1()应该没有问题,因为类位于Appointments.php文件中,然后尝试访问另一个文件?谢谢+特质?什么意思?我只想从后端api类调用Appoints类的函数,就是这样。如果您想从另一个类调用一个类的函数,只需将
Class1
的对象传递到
Class2
,然后使用它。