Codeigniter Controller无法使用helper中的函数

时间:2013-02-02 01:10:26

标签: php codeigniter custom-controls helper helpers

我有控制器

<?php

class Onetimescan extends CI_Controller{

    public function index() {
            #LOAD -->>>> LIB ###########
           $this->load->library('session');  ##    LOAD LIBS:  SESSION 
           $this->load->helper('simpledom');

           #LOAD -->>>> MODEL
           $this->load->model('scanmodel');
                $this->scanmodel->loadurlbasedonsessid($this->session->userdata('session_id')); // echo out inserted domain in loadurlbasedonsessid() func
                $sss= $this->session->userdata('tld'); // echo $sss;

       $siteToSearch = file_get_html($sss);
       foreach($siteToSearch->find('form') as $element){
            echo "<h1 style='color:red; '>".$element->action."</h1> <br />";
        }     
    }
}
?>

我在这一行收到Call to a member function find() on a non-object的致命错误:

   foreach($siteToSearch->find('form') as $element){

simpledom是我在顶部加载的一个帮助器(实际上称为simpledom_helper.php),它有一个file_get_html定义如下:

[http://pastebin.com/HaJtKfNb][1]

我在这里做错了什么?我尝试定义像public function file_get_html{}这样的函数,但是却犯了错误。

我通过添加:

修复了这一切
$prefix = "http://www.";
                //echo "SSS is:  ".$sss;
           $siteToSearch = file_get_html($prefix.$sss);

固定&GT;&GT; 该网址正在尝试get_file_contents(somedomain.com)并错过了http://www.作为完全限定的域名。此功能get_file_contents似乎需要http://www.

1 个答案:

答案 0 :(得分:1)

Helper函数应该像这样调用,因为它们不是对象:

$this->load->helper('simpledom');    
$siteToSearch = file_get_html($sss);
相关问题