0

I have the following piece of code in my Model:

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;
    }
}

And I created a class called 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();

However, I'm getting the following error:

<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>

Any thoughts? I have tried to access those values either as $site->data->database and as $site->data['database'] but both don't work.

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

The function 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;
}

Function getQuery:

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

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

Thanks

10
  • What is line 77 exactly? And how about removing the "$this->data = ArrayObject...." ? Commented Jun 14, 2012 at 21:39
  • May a little new is missing? Commented Jun 14, 2012 at 21:40
  • I have updated my question, now you guys are able to see line 77: Commented Jun 14, 2012 at 21:42
  • what does the getDatabase() function contain? Commented Jun 14, 2012 at 21:55
  • the function getDatabase has been included Commented Jun 14, 2012 at 21:59

2 Answers 2

1

Doing some investigation, I figured that $site is not a Site, but an Array.

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
)

Thus, there is not such thing like $site->data['site_id'], but $site['site_id'];

Sign up to request clarification or add additional context in comments.

Comments

0

I'm pretty sure your error message is complaining about the

$this->getDatabase

part of that line, not the $site-> aspect.

Are all of these functions on the Model, not the Class site?

when you are working in the model, $this-> has to stick to functions & vars from that class

1 Comment

getDatabase is part of the model.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.