我的模型中有以下代码:
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>
有什么想法?我尝试将这些值作为$site->data->database
和$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;
}
函数getQuery:
public function getQuery($str){
$data = array();
$query = $this->db->query($str);
if(!$query || $query->num_rows() == 0){
return false;
}
return $query;
}
由于
答案 0 :(得分: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] => <path-to-local-toolbox>
[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']
;
答案 1 :(得分:0)
我很确定您的错误消息是抱怨
$这 - &GT; getDatabase
该行的一部分,而不是$ site-&gt;方面。
所有这些功能都在Model上,而不是Class站点吗?
当您在模特中工作时,$ this-&gt;必须坚持功能和来自该班级的变种