【问题标题】:'Michelf\Markdown' class not found'Michelf\Markdown' 类未找到
【发布时间】:2016-08-12 07:10:34
【问题描述】:

我想使用Michelf Markdown Parser

<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);

$my_text = " a";

use \Michelf\Markdown;
$my_html = Markdown::defaultTransform($my_text);

echo "end";

不幸的是,它不起作用。我得到了错误:

致命错误: 未捕获的错误:在 /path/to/index.php:8 中找不到类 'Michelf\Markdown' 堆栈跟踪:在 /path 中抛出 #0 {main} /to/index.php8

我搜索了一下,发现有人had a similar issue。但是添加 'Michelf\' 并没有改变任何东西:

$my_html = \Michelf\Markdown::defaultTransform($my_text);

我收到了同样的错误信息。

这是我的文件树:

/path/to/
  |- index.php
  `- Michelf/
      |- Markdown.php
      |- MarkdownInterface.php
      `- […]

【问题讨论】:

    标签: php class markdown


    【解决方案1】:

    如果您以这种方式使用,则该软件包假设您使用自动加载器。我的意思是composer。我可能是错的,但是,如果你使用 composer,库的路径应该放在 /vendor 目录下

    require_once 'vendor/autoload.php';
    use Michelf\Markdown;
    
    $my_text = 'a';
    $my_html = Markdown::defaultTransform($my_text);
    

    或者,如果您不使用 composer,库的自述文件会告诉您如何使用它here

    require_once 'Michelf/Markdown.inc.php';
    use Michelf\Markdown;
    
    $my_text = 'a';
    $my_html = Markdown::defaultTransform($my_text);
    

    【讨论】:

      【解决方案2】:

      对我有用的是:

      composer require michelf/php-markdown
      composer dump-autoload
      

      【讨论】:

        猜你喜欢
        • 2016-12-11
        • 1970-01-01
        • 2018-05-03
        • 2020-10-15
        • 2019-05-07
        • 2018-04-15
        • 2014-01-12
        • 2014-04-21
        • 2017-12-16
        相关资源
        最近更新 更多