【问题标题】:Implement PHP Markdown class in a Wordpress Theme - Class 'Markdown' not found在 Wordpress 主题中实现 PHP Markdown 类 - 找不到类“Markdown”
【发布时间】:2013-10-10 11:24:56
【问题描述】:

我正在尝试在 Wordpress 主题中实现 php-markdown 类。

我想知道我是否以正确的方式解决这个问题。我已将Michelf 文件夹放入themeroot/_/inc/php/ 并在我的header.php 中有以下内容:

<?php

    set_include_path(get_include_path().PATH_SEPARATOR.get_template_directory().'/_/inc/php');

    spl_autoload_register(function($class){
        require preg_replace('{\\\\|_(?!.*\\\\)}', DIRECTORY_SEPARATOR, ltrim($class, '\\')).'.php';
    });

    use \Michelf\Markdown;

?>

然后我尝试像这样使用它:

&lt;?php echo Markdown::defaultTransform($someText); ?&gt;

这会导致错误:

致命错误:在中找不到类“Markdown” /目录/.../index.php 在第 11 行

如果我执行以下操作,它会起作用:

&lt;?php echo Michelf\Markdown::defaultTransform($someText); ?&gt;

这很奇怪,因为readme itself 不需要Michelf

只是想知道我是否打算以错误的方式包含这个类?

【问题讨论】:

    标签: php wordpress class markdown


    【解决方案1】:

    我认为文档中有错字。你需要 Michelf\ 因为它是命名空间的。看看 Markdown.php 的第 13 行,你就会明白了。

    【讨论】:

      猜你喜欢
      • 2014-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 2012-11-14
      相关资源
      最近更新 更多