【发布时间】:2016-01-06 23:28:49
【问题描述】:
我在课堂上有两个方法。
第一种方法get$id通过webservice获取特定item的3个参数。这是一个房地产系统的网络服务。我将使用这 3 个参数来查找相关项目。
到目前为止,一切正常。
我的问题是返回resemblant()方法的数据。
我实例化了object,我将$id 发送到features 方法并注册了属性。
$get 属性返回信息但$similar = $obj->resemblant() 没有返回。
我正在学习。
如何在
$similar中返回方法resemblant()中的数据?
<?php
require("Acesso.class.php");
class Semelhantes extends Acesso
{
public function features($id)
{
$postFields = '{"fields":["Codigo","Categoria","Bairro","Cidade","ValorVenda","ValorLocacao","Dormitorios","Suites","Vagas","AreaTotal","AreaPrivativa","Caracteristicas","InfraEstrutura"]}';
$url = 'http://danielbo-rest.vistahost.com.br/'.$this->vsimoveis.'/'.$this->vsdetalhes.'?key=' . $this->vskey;
$url .= '&imovel='.$id.'&pesquisa=' . $postFields;
$ch = curl_init($url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER , array( 'Accept: application/json' ) );
$result = curl_exec($ch);
$result = json_decode($result, true);
/**
* Paramentros para filtrar semelhança
* @var [type]
*/
$fcidade = str_replace(" ", "+", $result['Cidade']);
$fdorms = $result['Dormitorios'];
$fvalor = $result['ValorVenda'];
return array(
'cidade' => $fcidade,
'dorms' => $fdorms,
'valor' => $fvalor
);
}
public function resemblant()
{
$get = $this->features($id);
return $get['Cidade'];
}
}
/* Chamando as funções em outra parte do sistema */
$obj = new Semelhantes;
$features = $obj->features(2);
$similar = $obj->resemblant();
非常感谢
【问题讨论】:
-
var_dump($result)infeatures是否已填充 -
请不要在收到您的问题的有效答案后修改您的问题。它使答案看起来不必要和愚蠢。 SO 的主要目的是提供可搜索的问题和答案,以供其他人在遇到类似问题时使用
-
好的@RiggsFolly,非常抱歉!!!
-
您实例化了该对象并调用了
features()方法并使用$id传递它,并且您希望返回的值被填充到resemblant()方法中的$get中,其中在该方法的范围内@ 987654337@ 未定义? -
@Dagon var_dump 返回数据...puu.sh/mmemu/5679f4382a.png
标签: php arrays class methods instance