本文介绍了使用自定义类时找不到类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 https://github.com/nuovo/spreadsheet-reader 中的excel阅读器,它在应用程序文件夹中.

I am using excel reader from https://github.com/nuovo/spreadsheet-reader and it is in app folder.

现在,当我尝试使用以下代码从HomeController.php访问它时.

Now when I try to access it from HomeController.php using following code.

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;

use App\spreadsheet_reader\php_excel_reader\excel_reader2;
use App\spreadsheet_reader\SpreadsheetReader;

class HomeController extends Controller
{
    public function index()
   {
        require_once(base_path().'/app/spreadsheet_reader/php_excel_reader/excel_reader2.php');

       $Reader = new \App\spreadsheet_reader\SpreadsheetReader(base_path().'/UnRegisterClient.xlsx');
   }
}

然后它给了我以下错误.

Then it gives me following error.

找不到类'App \ spreadsheet_reader \ SpreadsheetReader'

Class 'App\spreadsheet_reader\SpreadsheetReader' not found

任何建议如何解决此问题?我是说我该如何使用自定义类?

Any suggesstion how I can solve this? I mean how I can use my custom class?

推荐答案

我认为 SpreadsheetReader 未在命名空间中定义.您应该只调用 new \ SpreadsheetReader(...)或添加使用SpreadsheetReader ,然后将其命名为 new SpreadsheetReader()

I think the SpreadsheetReader is not defined in the namespace. You should call just new \SpreadsheetReader(...) or add use SpreadsheetReader and then call it new SpreadsheetReader()

这篇关于使用自定义类时找不到类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 14:30