【问题标题】:having difficulty setting up phpepub library难以设置 phpepub 库
【发布时间】:2016-06-30 06:53:19
【问题描述】:

我已经通过 composer 下载 phpepub 然后开始运行测试 file 以了解如何使用该库,但它会引发错误

找不到类“com\grandt\EPub”

然后我开始查看测试文件夹并打开文件exampletest1.php,它也抛出了一个错误,说

找不到类“PHPePub\Core\Logger”

我正在考虑一种解决此错误的方法,现在检查了权限(这很好),该文件也存在于文件夹中 这是库的文件结构

phpepub/
	legacy/
	src/
		PHPePub/
			Core/
				structure/
				Logger.php
				.
				.
				.
			Helpers/
	tests/
		demo/
		EPub.Example1.php
		.
		.
		.
		composer.json 
	vendor/
		composer/
		grandt/
		phpzip/
		.
		.
		.
	README.md
	test.php 
	ReadMe.html 
	.
	.
	.
	.
	composer.json 

【问题讨论】:

    标签: php epub


    【解决方案1】:

    您需要在使用 composer 安装的组件的每个文件中要求 vendor/autoload.php 文件。

    test.php:

    <?php
    
    require_once __DIR__.'/vendor/autoload.php';
    
    //...
    

    测试/exampletest1.php

    <?php
    
    require_once __DIR__.'/../vendor/autoload.php');
    
    //...
    

    请参阅 Composer 文档中的 Basic Usage - Autoloading

    在您的项目中使用

    在项目的根目录中,将"grandt/phpepub": "&gt;=4.0.3" 添加到您的作曲家依赖项并运行composer install

    假设你的项目目录结构是:

    project
      vendor
      public
        index.php
      composer.json
    

    运行composer install时,Composer会在项目根目录下创建一个目录vendor/,并生成一个autoload文件vendor/autoload.php

    要使用 index.php 中已安装的库,需要自动加载文件:

    index.php:

    <?php
    
    require_once __DIR__."/../vendor/autoload.php";
    
    //...
    

    如需快速详细解释,请尝试阅读Juan Treminio - Composer Namespaces in 5 minutes

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-10
      • 2015-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-20
      • 1970-01-01
      相关资源
      最近更新 更多