将外部库添加到Symfony2项目 [英] Add external libraries to Symfony2 project

查看:74
本文介绍了将外部库添加到Symfony2项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个外部库(PHP简单DOM分析器, http://simplehtmldom.sourceforge. net/index.htm )添加到Symfony2项目中.我上了一个教程,该教程说明了如何将第三方库包含到Symfony2中 http://www.kiwwito.com/article/add-third-party-libraries-to-symfony-2 .

I am trying to add an external library (PHP Simple DOM Parser, http://simplehtmldom.sourceforge.net/index.htm) to a Symfony2 project. I took a tutorial that explains how to include third party libraries to Symfony2 http://www.kiwwito.com/article/add-third-party-libraries-to-symfony-2.

我设置了一个类文件,例如:

I set up a class file like:

# vendor/phpsimpledom/lib/Phpsimpledom/simple_html_dom.php

require_once __DIR__.'/src/simple_html_dom.php';

class Phpsimpledom_Phpsimpledom extends simple_html_dom_node {
}

并在我的自动加载器(autoload.php)中注册了我的课程:

and registered my class in my Autoloader (autoload.php):

$loader->registerNamespaces(array(
...
'Phpsimpledom' => __DIR__.'/../vendor/phpsimpledom/lib/',
...
),));

我正尝试致电:

$phpsimpledom = new \Phpsimpledom();

但是这使我遇到了一个错误(致命错误:找不到类'simple_html_dom_node').

but this throughs me an error (Fatal error: Class 'simple_html_dom_node' not found).

但是:库的主文件(simple_html_dom.php)由不属于类的函数组成.

However: The main file of the library (simple_html_dom.php) consists of functions that do not belong to a class.

当我尝试直接使用该文件时,它也不起作用:

When I try to use the file directly, it also doesn't work:

    $loader->registerNamespaces(array(
...
'Phpsimpledom' => __DIR__.'/../vendor/phpsimpledom/lib/Phpsimpledom/src/simple_html_dom.php',
...
),));

有任何提示吗?

谢谢!

推荐答案

您正在尝试注册名称空间,但是您的类没有名称空间.尝试向其中添加名称空间或使用RegisterPrefixes().

You're trying to register a namespace but your class has no namespace. Try adding a namespace to it or use RegisterPrefixes().

顺便说一句:您是否知道Symfony组件之一基本上在做与php simpledom相同的事情?它叫做DomCrawler,它同时支持xpath和CSS选择器.

BTW: did you know that one of the Symfony components is basically doing the same thing as php simpledom? It's called DomCrawler and it has a support for both xpath and CSS selectors.

这篇关于将外部库添加到Symfony2项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆