我想知道有什么方法可以使此代码更微妙吗?
前任
public function hookDisplayHeader()
{
if(Tools::getValue('controller')=='index'){
$this->context->controller->addCSS(($this->_path).'something.css', 'all');
}
if(Tools::getValue('controller')=='cms'){
$this->context->controller->addCSS(($this->_path).'something.css', 'all');
}
if(Tools::getValue('controller')=='product'){
$this->context->controller->addCSS(($this->_path).'something.css', 'all');
}
if(Tools::getValue('controller')=='category'){
$this->context->controller->addCSS(($this->_path).'something.css', 'all');
}
}
简单
public function hookDisplayHeader()
{
if(Tools::getValue('controller')=='index AND product AND cms AND category'){
$this->context->controller->addCSS(($this->_path).'something.css', 'all');
}
}
此代码不起作用:(
使用 in_array();
public function hookDisplayHeader()
{
$values = array('index','cms','product','category');
if(in_array(Tools::getValue('controller'), $values)){
$this->context->controller->addCSS(($this->_path).'something.css', 'all');
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句