【发布时间】:2011-11-30 00:19:23
【问题描述】:
我对模块化编程很陌生。
我无法在模块中设置变量,但仅限于特定函数。
我已经(删除了无用的东西):
class Products extends Modules {
private $resultsFound;
function __construct() {
parent::__construct();
}
public function getResultsFound() {
return $this->resultsFound;
}
private function setResultsFound($resultsFound) {
$this->resultsFound = $resultsFound;
}
}
我在模块中有 2 个公共函数,它们都做的事情差不多,但一个会将 var 设置为 $this->setResultsFound(12) 而一个不会。
public function sortSearchBar($categoryID, $brandID, $sort = false, $limit = false, $search = false){
foreach ($this->sortAwway as $key => $val) {
$optionItems[] = '<option value="'.$key.'"'. (($sort == $key) ? ' selected="selected"' : '' ) .'>'.$this->htmlspecialchars($val).'</option>';
}
foreach ($this->searchLimit as $key => $val) {
$limitItems[] = '<option value="'.$key.'"'. (($limit == $key) ? ' selected="selected"' : '' ) .'>'.$this->htmlspecialchars($val).'</option>';
}
$this->setResultsFound(12); //works
return '
<form action=...
</form>';
}
public function showProductItemList($categoryID, $brandID = false, $page, $sort = false, $limit = false, $search = false, $cleanURL = true){
//echo $this->echoArray($this->getProductsForCategory($categoryID, $brandID));
$q = $this->getProductsForCategory($categoryID, $brandID, $sort, $search);
$this->setResultsFound(12); //doesn't work
return $this->formatProductResults($q, $limit, $cleanURL, $page);
}
有人知道为什么吗?
干杯, 里斯
【问题讨论】: