php - I am getting Fatal error: Using $this when not in object context -
hi using code below, know works in page on site, purpose have put within standalone button runs script server side, not working , getting fatal error: using $this when not in object context
(the $$postcode= $params["value1"]; result previous javascript fetches current field (postcode) add screen, works , tested, rest of code.
id grateful alternatives?
$postcode= $params["value1"]; //set post code variables $key = "xxxx-xxxx-xxxx-xxxx"; $searchterm = $postcode; $this->key = $key; $this->searchterm = $searchterm; //build url request $url = "http://services.postcodeanywhere.co.uk/postcodeanywhere/interactive/find/v1.10/xmla.ws?"; $url .= "&key=" . urlencode($this->key); $url .= "&searchterm=" . urlencode($this->searchterm); //make request postcode anywhere , parse xml returned $file = simplexml_load_file($url); //check error, if there 1 throw exception if ($file->columns->column->attributes()->name == "error") { throw new exception("[id] " . $file->rows->row->attributes()->error . " [description] " . $file->rows->row->attributes()->description . " [cause] " . $file->rows->row->attributes()->cause . " [resolution] " . $file->rows->row->attributes()->resolution); } //copy data if ( !empty($file->rows) ) { foreach ($file->rows->row $item) { $this->data[] = array('id'=>$item->attributes()->id,'streetaddress'=>$item->attributes()->streetaddress,'place'=>$item->attributes()->place); $sql = "insert tempaddress (id, streetaddress, place, postcode) values ('".$item["id"]."', '".$item["streetaddress"]."', '".$item["place"]."','$searchterm')"; customquery($sql); }} $result["postcoderesult"]=$postcode;
to use $this-> have make class , oop programming. don't have class use ($this) if have key property in class have make instance class
$obj = new class;
and use properties
$obj->key
$this use when have call methods or properties in class, have class key property , if have access peropery have ro make instance class
Comments
Post a Comment