Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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
在CakePHP中导入自定义类_Php_Cakephp - Fatal编程技术网

在CakePHP中导入自定义类

在CakePHP中导入自定义类,php,cakephp,Php,Cakephp,我有2个自定义PHP类放在Lib文件夹中。在控制器中,我需要导入以下类Custom2,这是导入类Custom。我可以通过实例化这个类并在控制器的操作中调用它的方法来使用classCustom2,如下所示: <?php App::import('Lib', 'custom2'); class TestController extends AppController { function index() { $custom = new Custom2();

我有2个自定义PHP类放在Lib文件夹中。在控制器中,我需要导入以下类
Custom2
,这是导入类
Custom
。我可以通过实例化这个类并在控制器的操作中调用它的方法来使用class
Custom2
,如下所示:

<?php
App::import('Lib', 'custom2');
class TestController extends AppController {

    function index() {
         $custom = new Custom2();
         $test = $custom->test();
    }

}

?>

两个类都在同一个文件夹(Lib)中。这里出了什么问题?

您可以将它们放在
供应商
文件夹中,如中所述


另一个选项是放入
Lib
文件夹

您可以将它们放入
供应商
文件夹,如中所述


另一种选择是放入
Lib
文件夹

显然,您可以将它们放入一个包中并使用它,或者将它们放入一个供应商子目录,然后导入:显然,您可以将它们放入一个包中并使用它,或者将它们放入一个供应商子目录,导入:但是我怎样才能在Custom2.php中包含Custom.php呢?你可以使用
include\u一次
我试过了,但是没有用。现在它看起来像上面编辑过的帖子。但是我怎样才能在Custom2.php中包含Custom.php呢?你可以使用
include\u一次
我试过了,但是没有用。现在它看起来像上面编辑过的帖子。
Custom2.php:

<?php
include_once 'Custom.php';

class Custom2 {
    public function test() {
         $test = new Custom(); // this is not working               
    }
}
?>
Custom.php:

<?php

class Custom {
    public function test() {
        return "test";
    }
}
?>
App::import('Vendor', 'custom2');