我是PHP的核心。我遇到了麻烦。
Notice on line 328 in file modules/swipe/swipe.php
[8] Undefined property: Swipe::$_postErrors
public function getContent() {
$this->_html = '<img src="'.$this->_p otocol.$this->context->shop->domain.$this->_path.'logo-big.png" style="margin-bottom:20px" />';
if (Tools::isSubmit('btnSubmit')) {
$this->_postValidation();
if (!count($this->_postErrors)) **((Line 328))**
$this->_postProcess();
else
foreach ($this->_postErrors as $err)
$this->_html .= '<div class="alert error">' . $err . '</div>';
}
else
$this->_html .= '<br />';
$this->_displayTop();
$this->_displayForm();
return $this->_html;
}
}
你能帮我解决这个问题吗?我附上了swipe.php文件。
谢谢。
将代码更改为此
public function getContent() {
$this->_html = '<img src="'.$this->_p otocol.$this->context->shop->domain.$this->_path.'logo-big.png" style="margin-bottom:20px" />';
if (Tools::isSubmit('btnSubmit')) {
$this->_postValidation();
if (isset($this->_postErrors)
{
if (!count($this->_postErrors))
$this->_postProcess();
else
foreach ($this->_postErrors as $err)
$this->_html .= '<div class="alert error">' . $err . '</div>';
}
}
else
$this->_html .= '<br />';
$this->_displayTop();
$this->_displayForm();
return $this->_html;
}
}
当您访问一个属性&属性不存在,发生此错误。在生产中,这个错误不会显示,因为在生产中不会显示任何错误,但在开发中,最好显示所有错误。
使用isset
函数检查属性是否存在。
将if条件更改为
if (empty($this->_postErrors))
$this->_postProcess();
这样,在$this->_postErrors
未定义的情况下,您的条件也会起作用。