问题描述
我试图在Wordpress主题中实施类。
I am trying to implement the php-markdown class in a Wordpress theme.
我想知道我是否正确的方式。我把 Michelf
文件夹放入 themeroot / _ / inc / php /
header.php 我有以下:
I am wondering if I am going about this the right way. I have put the Michelf
folder into themeroot/_/inc/php/
and in my header.php
I have the following:
<?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;
?>
然后我试图这样使用:
<?php echo Markdown :: defaultTransform($ someText);
<?php echo Markdown::defaultTransform($someText); ?>
致命错误:在第11行中未在
/directories/.../index.php
中找到类'Markdown'
如果我执行以下操作,它会工作:
It works if I do the following:
<?php echo Michelf\Markdown :: defaultTransform someText); ?>
这是奇数,因为不需要 Michelf
?
Which is odd because the readme itself doesn't require the Michelf
?
只是想知道我是否会将这个类包含在错误的方式中?
Just wondering if I am going about including this class the wrong way?
推荐答案
文档。你需要Michelf \,因为它是命名空间。看看Markdown.php,第13行,你会看到。
I think there is a typo in the docs. You need the Michelf\ because it's namespaced. Look at Markdown.php, line 13, and you'll see.
这篇关于在Wordpress主题中实现PHP Markdown类 - 没有找到类'Markdown'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!