2015-12-19 41 views
0

这里我有一个Crypt.php文件。它的一个类有两个函数,并将其存储在“\ backend \ components”文件夹中。Yii2 -windows 10 xampp路径错误

"Unknown Class – yii\base\UnknownClassException Unable to find 'backend\components\Crypt' in file: E:\xampp\htdocs\pope-Admin/backend/components/Crypt.php. Namespace missing?" in this path half of them have slash(/) and half of the part have back slash() how to solve it?

+0

此错误通常意味着,因为它说,你还没有宣布在crypt.php文件命名空间。 –

回答

0

使用include(_once)或require(_once)关键字包括:我使用此代码

$security = new \backend\components\Crypt(); 

在运行时,我得到这个错误在我的控制器调用这个文件(类) Crypt.php文件,然后使用new Crypt()。你不能定义类的实例,你必须包含包含类代码的filw,然后才能使用new关键字。

1

在你Crypt类文件,包括命名空间声明,如下所示:

<?php 

    namespace backend\components; 

    class Crypt { 
     ... 
    } 

?>