我对模块化编程非常新鲜。
我在模块中设置变量时遇到问题,但仅限于特定功能。
我有(无用的东西被删除):
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);
}
有谁知道为什么?
干杯, 里斯