摘要:TEEBB在前台页面的twig模板中添加了teebb_core全局对象,这个对象可以获取全局系统设置,可将获取到的设置信息存入缓存。 参考代码: // \Teebb\CoreBundle\Twig\GlobalVariables /** * 使用此方法获取T...
TEEBB在前台页面的twig模板中添加了teebb_core全局对象,这个对象可以获取全局系统设置,可将获取到的设置信息存入缓存。
参考代码:
// \Teebb\CoreBundle\Twig\GlobalVariables
/**
* 使用此方法获取TEEBB的设置值
* @param string $optionName
* @return mixed
* @throws InvalidArgumentException
*/
public function getOptionValue(string $optionName)
{
if (!$this->hasCache($optionName)) {
$optionRepo = $this->entityManager->getRepository(Option::class);
$option = $optionRepo->findOneBy(['optionName' => $optionName]);
return $this->getCache($optionName, $option->getOptionValue());
}
return $this->getCache($optionName);
}
TEEBB使用\Teebb\CoreBundle\Entity\Option类对一些设置参数进行管理。
默认对左图的“系统设置”使用\Teebb\CoreBundle\Entity\Options\System类进行管理,并将此类以key-value的形式存储,key值为:system
参考如下代码:
{% set system = teebb_core.optionValue('system') %}
可获取system值,并在取值时进行了缓存。参看上文getOptionValue方法。