【问题标题】:xml class cannot be found找不到xml类
【发布时间】:2017-06-07 08:05:04
【问题描述】:

我正在尝试使用fluidxml 来测试我是否可以使用它,但我无法让它开始工作,我正在使用codeigniter 框架。我克隆了 repo https://github.com/servo-php/fluidxml 并将其添加到我创建的名为第三方的文件夹中。然后这里是函数的代码

public function xmltrial(){
        $this->load->helper('file'); 
        require_once(APPPATH.'third_party/fluidxml/source/FluidXml.php');

        $book = new FluidXml();
        $book->add([ 'title'  => 'The Theory Of Everything',
             'author' => 'S. Hawking',
             'chapters' => [
                    [ 'chapter' => [
                            '@id' => '1',
                            '@'   => 'Ideas About The Universe' ] ],
                    [ 'chapter' => [
                            '@id' => '2',
                            '@'   => 'The Expanding Universe' ] ],
           ]]);

        echo $book;
    }

所以我得到了两个错误,一个是致命错误:甚至找不到“FluidXml”类,第二个是如果我在我的 xmltrial 函数中使用 use function \FluidXml\fluidxml; use function \FluidXml\fluidns; use function \FluidXml\fluidify; 所有这些字符,它会在它们上显示一个红色错误。

【问题讨论】:

    标签: php xml codeigniter


    【解决方案1】:

    您应该使用 composer 来管理您的依赖项。安装作曲家,然后通过键入将 FluidXml 安装到供应商文件夹中

    composer require servo/fluidxml

    在命令行中。然后就可以了

    require_once 'vendor/autoload.php'

    在您的 index.php 中,您可以忘记必须在文件中使用 require!您只需将相关的 use 语句放在您的命名空间声明下。在您的情况下,

    use FluidXml\FluidXml;

    现在你可以开始给你的班级打电话了!

    请参阅Packagist了解作曲家包的详细信息https://packagist.org/packages/servo/fluidxml

    如果您还没有https://getcomposer.org/,请参阅 Composer 网站以将 composer 加入 CodeIgniter 中

    【讨论】:

      猜你喜欢
      • 2013-11-28
      • 2015-08-17
      • 2013-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-23
      相关资源
      最近更新 更多