Php 在Codeigniter 3.0.1中自动加载并使用简单的HTML dom外部库
我在CodeIgniter 3.0中包含/使用外部库时遇到问题。这就是我到目前为止所做的: 我已将simple_html_dom.php文件放在我的应用程序/库文件夹中 然后我用这行代码自动加载它Php 在Codeigniter 3.0.1中自动加载并使用简单的HTML dom外部库,php,codeigniter,codeigniter-3,Php,Codeigniter,Codeigniter 3,我在CodeIgniter 3.0中包含/使用外部库时遇到问题。这就是我到目前为止所做的: 我已将simple_html_dom.php文件放在我的应用程序/库文件夹中 然后我用这行代码自动加载它 /* example of CI $autoload['libraries'] = array('user_agent' => 'ua'); */ $autoload['libraries'] = array('simple_html_dom' => 'shd'); 这是我的控制器
/*
example of CI
$autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array('simple_html_dom' => 'shd');
这是我的控制器
public function index()
{
$html = $this->shd->str_get_html('<html><body>Hello!</body></html>');
var_dump($html);
die();
$this->load->view('parser');
}
关于简单html dom的文档可以在这个网站上找到
对我来说,它看起来像图书馆被加载了,但我不能使用它的功能。
我希望有人能帮忙。提前谢谢你 您可以使用
$this->load->library("simple_html_dom"); //class name should come here
并确保simple\u html\u dom.php
类名为simple\u html\u dom
试试这个-
$autoload['libraries']=array('simple_html_dom') 我找到了解决办法。在检查了简单HTMLDOM的文档之后,我发现您也可以使用面向对象的方式。我的控制器现在看起来像这样:
$html = new simple_html_dom();
$html->load('<html><body>Hello!</body></html>');
var_dump($html);
您可以这样做:
$this->load->library("simple_html_dom");
$this->simple_html_dom->your_method();
抱歉,同样的问题消息:调用未定义的方法simple\u html\u dom::str\u get\u html(),我想问题出在您的文件中。不是在图书馆自动加载。是的,我正在考虑这个问题。因为simple_html_dom在文件中有许多类。如果我在没有codeigniter的情况下尝试这个文件,它会工作,但是在codeigniter中运行会是一个问题。我找到了一个解决方案。您必须先创建对象,然后才能使用函数!无论如何谢谢你!你能再解释一下吗?因为如果我只是在我的控制器中加载这个库,我也会遇到同样的问题。可能是因为这个简单的html dom文件中有很多类,所以会有问题吗?
object(simple_html_dom)[17]
public 'root' =>
object(simple_html_dom_node)[18]
public 'nodetype' => int 5
public 'tag' => string 'root' (length=4)
public 'attr' =>
array (size=0)
empty
public 'children' =>
array (size=1)
0 =>
object(simple_html_dom_node)[19]
...
public 'nodes' =>
array (size=1)
0 =>
object(simple_html_dom_node)[19]
...
public 'parent' => null
public '_' =>
array (size=2)
0 => int -1
1 => int 4
public 'tag_start' => int 0
private 'dom' =>
&object(simple_html_dom)[17]
public 'nodes' =>
array (size=4)
0 =>
object(simple_html_dom_node)[18]
public 'nodetype' => int 5
public 'tag' => string 'root' (length=4)
public 'attr' =>
array (size=0)
...
public 'children' =>
array (size=1)
...
public 'nodes' =>
array (size=1)
...
public 'parent' => null
public '_' =>
array (size=2)
...
public 'tag_start' => int 0
private 'dom' =>
&object(simple_html_dom)[17]
$this->load->library("simple_html_dom");
$this->simple_html_dom->your_method();