モデルに次のコードがあります。
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
asと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;
}
関数getQuery:
public function getQuery($str){
$data = array();
$query = $this->db->query($str);
if(!$query || $query->num_rows() == 0){
return false;
}
return $query;
}
ありがとう