我有以下课程,我在其中添加了属性$user
。
include_once(__CA_LIB_DIR__."/ca/Search/BaseSearch.php");
include_once(__CA_LIB_DIR__."/ca/Search/ObjectSearchResult.php");
class ObjectSearch extends BaseSearch {
# ----------------------------------------------------------------------
/**
* Which table does this class represent?
*/
protected $ops_tablename = "ca_objects";
protected $ops_primary_key = "object_id";
public $user;
# ----------------------------------------------------------------------
public function &search($ps_search, $pa_options=null, $user) {
return parent::doSearch($ps_search, new ObjectSearchResult(), $pa_options);
}
# ----------------------------------------------------------------------
}
?>
在以下代码中,我无法将$user
属性传递给搜索方法。我尝试使用$user
,$this->user
和new ObjectSearch($user)
。作为PHP的新手,我知道我在问一个天真的问题,但我不能自己解决,相信我,我试了几天。我怎么能做到这一点?
$po_request = $this->getVar('request');
$vs_widget_id = $this->getVar('widget_id');
$user = $this->getVar('user');
$o_search = new ObjectSearch();
$result = $o_search->search('created.$user.:"2013"');
$count = 1;
while($result->nextHit()) {
print "Hit ".$count.": "."<br/>\n";
print "Idno: ".$result->get('ca_objects.idno')."<br/>\n";
print "Name: ".$result->get('ca_objects.preferred_labels.name')."<br/>\n";
$count++;
}
?>
答案 0 :(得分:0)
不要将双引号与单引号混淆。你必须在这里使用连接或双连接:
$result = $o_search->search('created ' . $user . ': 2013');
或
$result = $o_search->search("created $user: 2013");
答案 1 :(得分:0)
public function &search($ps_search, $pa_options=null, $user)
它有一些问题:
$this
所以写:
public function &search($ps_search, $pa_options=null) {
return parent::doSearch($ps_search, new ObjectSearchResult($this->user), $pa_options);
}
或者您可能需要$user
课程属性,只需撰写$this->user
。
$this
始终设置在对象上下文中:您不需要自己传递它。