对“调用未定义函数”进行故障排除将 Markdown 添加到项目时
我正在尝试向我的 Symfony 项目(Symfony 版本 1.3.3)添加一些 Markdown 功能。
为了实现这一点,我已经将 Markdown 库包含到 lib/vendor 目录中。另外,我在之前的库的 autoload.yml 中添加了需要的配置。
但是,我遇到了致命的 PHP 错误:
调用未定义的函数 Markdown()
如何解决此问题?
I'm trying to add some Markdown capabilities to my Symfony project (Symfony version 1.3.3).
To accomplish that, I had already included the Markdown library into lib/vendor
directory. Also, I added the need configuration in the autoload.yml for the previous library.
However, I'm getting a fatal PHP error:
Call to undefined function Markdown()
How can I resolve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
symfony 自动加载器从名为
.class.php
的 php 文件加载类。如果您使用 mitchelf.com 中的 markdown.php 文件,它不遵循命名方案,也不包含名为 Markdown 的类,事实上:它有一个名为 Markdown 的函数。由于我上面描述的原因,Symfony 甚至没有尝试加载它。您必须手动包含它。我建议您查看 http://www.symfony-project.org/plugins/sfEasyMarkdownPlugin 。
The symfony autoloader loads classes from php files named like
<classname>.class.php
. If you're using the markdown.php file from mitchelf.com, it does not follow the naming scheme, nor does it contain a class called Markdown, as a matter of fact: it has a function called Markdown.Symfony isn't even trying to load it, for reasons I described above. You will have to include it manually. I suggest you have a look at http://www.symfony-project.org/plugins/sfEasyMarkdownPlugin.
我不建议为如此简单的功能安装插件。如果你有一些真实的例子,你就不难理解了。
有一个基于 symfony 的开源项目,名为 Bookeet。它嵌入了 MarkDowm 功能。它使用 markitup 作为 markdown 编辑器。它使用 php markdown 将 markdown 代码转换为 html 代码。
为了节省您的时间,请直接转到 Bookeet 项目的变更集 29f0ba1807(很抱歉,我无法发布超链接,因为 SO 不允许新用户发布多个超链接)。您可以清楚地看到应该做什么才能向您的网站添加 Markdown 功能。
I do NOT suggest installing a plugin for such a simple feature. It is not hard for you to figure it out if you have some real examples.
There is an open source project based on symfony named Bookeet. It has embedded MarkDowm feature. It uses markitup as the markdown editor. And it uses php markdown to convert markdown code to html code.
To save your time, go directly to changeset 29f0ba1807 of the Bookeet project(I am sorry that I can't post the hyperlink because SO doesn't permit new user to post more than one hyperlink). You could see clearly what should be done in order to add markdown feature to your website.