0

我的模型中有以下代码:

public function getSite()
{
    $this->load->library('site');
    $data = array();
    $str = "SELECT * FROM sitematrix_sites";
    $query = $this->getQuery($str);
    if($query){ 
        foreach($query->result() as $row){
            $site = new Site();
            array_push($data, $site->load($row));
        }

        foreach($data as $site){
            $site->data['database'] = $this->getDatabase($site->data['site_id']);
            $site->data['baseline'] = $this->getBaseline($site->data['site_id']);
        }

        return $data;
    }
    else{
        return false;
    }
}

我创建了一个名为 site 的类:

class Site{

public $data;

public function __contruct(){

    $this->data = ArrayObject(array(), ArrayObject::STD_PROP_LIST);

    $this->data['site_id']                      =   '';
    $this->data['site']                         =   '';
    $this->data['site_code']                    =   '';
    $this->data['tc_10']                        =   array();
    $this->data['tc9x']                         =   array();
    $this->data['tc8x']                         =   array();
    $this->data['tc2008']                       =   array();
    $this->data['eng_2005']                     =   array();
    $this->data['database']                     =   array();
    $this->data['baseline']                     =   array();

但是,我收到以下错误:

<p>Severity: Notice</p>
<p>Message:  Trying to get property of non-object</p>
<p>Filename: models/sitematrix_model.php</p>
<p>Line Number: 77</p>

有什么想法吗?我曾尝试以 as$site->data->database和 as访问这些值,$site->data['database']但两者都不起作用。

line 77:  $site->data['database'] = $this->getDatabase($site->data['site_id']);

函数getDatabase:

public function getDatabase($id){
    $database = array();
    $str = "SELECT * FROM site_database where site_id='$id'";
    $query = $this->getQuery($str);
    if($query){
        foreach($query->result() as $row){
            array_push($database, $row->name);
        }
    }

    return $database;
}

函数获取查询:

public function getQuery($str){
    $data = array();
    $query = $this->db->query($str);

    if(!$query || $query->num_rows() == 0){
        return false;
    }
    return $query;
}

谢谢

4

2 回答 2

1

做了一些调查,我认为这$site不是一个Site,而是一个数组。

Array ( [site_id] => 1
[site] => Ames
[site_code] => ame
[windows_ref_unit_location] => \\plm\amnas\tc_ref
[unix_ref_unit_location] => /tc_ref
[windows_rte_location] => \\plm\amnas\tc_rte
[unix_rte_location] => /tc_rte
[windows_toolbox_location] => &lt;path-to-local-toolbox&gt;
[unix_toolbox_location] => /tc_ref/TOOLBOX
[UGS_LICENSE_SERVER] => 28000@cinxflex1,28000@cinxflex2,28000@cinxflex3
[UGII_LICENSE_FILE] => 27000@cinxflex1,27000@cinxflex2,27000@cinxflex3
[unix_dev_units] => /tc_work
[unix_devop_path] => /usr/site/devop_tools
[netapp_filer] => \\plm\amnas
[perforce_proxy_path] => /p4p/p4p_cache
[primary_contact] => Philomena Siddle
[secondary_contact] => Mathieu Sarrazy
[num_users] => 7
)

因此,没有这样的东西$site->data['site_id'],但是$site['site_id']

于 2012-06-14T22:48:16.960 回答
0

我很确定您的错误消息是在抱怨

$this->getDatabase

该行的一部分,而不是 $site-> 方面。

所有这些功能都在模型上,而不是在课堂上吗?

当您在模型中工作时,$this-> 必须坚持使用该类中的函数和变量

于 2012-06-14T22:26:48.107 回答