我对magento使用的主题是“Love Fashion”,但是这仅仅是为了解如果有人遇到过与此主题相同的问题之前的信息。调试一个未定义的变量,Magento PHP
我收到以下错误Notice: Undefined variable: deal
。两行上,50和61发生了错误 - 但是该错误两次上显示出线路50例如:
Notice: Undefined variable: deal on line 50
Notice: Undefined variable: deal on line 50
Notice: Undefined variable: deal on line 61
这发生以下代码(起始于线49,线67上结束):
public function addFilter($filterName,$filtervalue,$condition='='){
if ($deal instanceof Sm_Deal_Model_Deal){
$deal = $deal->getId();
}
if (!$this->_joinedFields){
$this->joinFields();
}
$this->getSelect()->where('deal.'.$filterName.' '.$condition.' ?', $filtervalue);
return $this;
}
public function OrderbyAdd($orderName,$ordervalue){
if ($deal instanceof Sm_Deal_Model_Deal){
$deal = $deal->getId();
}
$this->getSelect()->order('deal.'.$orderName.' '.$ordervalue);
return $this;
}
所以我的问题是,我如何解决在这种情况下未定义的变量?
例如,我用下面的代码早在同一文件中,但是这并没有给任何错误:(开始于第26行,47行结束)
public function addDealFilter($deal){
if ($deal instanceof Sm_Deal_Model_Deal){
$deal = $deal->getId();
}
if (!$this->_joinedFields){
$this->joinFields();
}
$this->getSelect()->where('related.deal_id = ?', $deal);
return $this;
}
public function joinFieldsdeal(){
$this->getSelect()->join(
array('deal' => $this->getTable('deal/deal')),
'deal.entity_id = related.deal_id',
array('deal.end_date','deal.start_date','deal.name')
);
$this->_joinedFields = true;
return $this;
}
问题并不是"Reference: What is variable scope, which variables are accessible from where and what are “undefined variable” errors?"的重复,因为这只是解释了函数的基础 - 在这里并不是这样。
[参考:什么是变量作用域,哪些变量可以从哪里访问,什么是“未定义变量”错误?](http://stackoverflow.com/questions/16959576/reference-what-is-variable -scope-which-variables-are-accessible-from-where-and) – IMSoP
嗨IMSoP - 它可能是同样的问题,但你链接到的问题,只定义了函数的基础,我已经知道了。我上面列出的代码,我不明白范围,因为这不是我清楚,因为你连接的范围。 – Patrick
考虑到在相关答案中解释的范围规则,您认为'$ deal'将来自通知中突出显示的行吗? – IMSoP