src/AppBundle/Twig/DictionaryExtension.php
(开头部分) 1KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace AppBundle\Twig;
use Codeages\Biz\Framework\Context\Biz;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DictionaryExtension extends \Twig_Extension
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var Biz
*/
protected $biz;
protected $pageScripts;
public function __construct($container, Biz $biz)
{
$this->container = $container;
$this->biz = $biz;
}
public function getFunctions()
{
$options = array('is_safe' => array('html'));
return array(
new \Twig_SimpleFunction('dict_select_options', array($this, 'dictSelectOptions'), $options),
);
}
public function dictSelectOptions($type, $selected = null, $empty = null)
{
$choices = $this->container->get('codeages_plugin.dict_twig_extension')->getDict($type);
$html = '';
if (!is_null($empty)) {
if (is_array($empty)) {
foreach ($empty as $key => $value) {
$html .= "<option value=\"{$key}\">{$value}</option>";
}
} else {
$html .= "<option value=\"\">{$empty}</option>";
}
}
foreach ($choices as $value => $name) {
if ($selected === $value) {
$html .= "<option value=\"{$value}\" selected=\"selected\">{$name}</option>";
} else {
$html .= "<option value=\"{$value}\">{$name}</option>";
}
}
return $html;
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。