//创建块函数方法,用于替换文本中的值
function smarty_block_get_cates($params, $content, &$_sm, &$repeat) { if (!$repeat) { $ci = &get_instance(); $cates = $ci->db->get('category')->result_array(); $cates = get_data($cates); $ss = $ci->db->list_fields('category'); $str = ''; foreach ($cates as $k => $v) { $tmp = trim($content); foreach ($ss as $key => $val) { if ($val == 'ctype') { if ($v[$val] == 0) $v[$val] = '频道封面页'; if ($v[$val] == 1) $v[$val] = '列表页'; if ($v[$val] == 2) $v[$val] = '外链'; } if ($val == 'cname') { $v[$val] = str_repeat('---', $v['level'] * 2) . $v[$val]; if (isset($params['val'])) { if (trim($v[$val]) != trim($params['val'])) { $tmp = str_replace("selected", "", $tmp); } } } $tmp = str_replace("field.$val", $v[$val], $tmp); } $str .= $tmp; } return $str; } }
function add_child() { $cid = $this->uri->segment(4); $cate = $this->db->where('id', $cid)->get('category')->row_array(); //根据ID,获取需要被选中的选项名称 $this->_sm->assign('cate', $cate); $this->_sm->display('category/add_child.html'); }
前端
<select class="form-select" aria-label="Default select example"> <option value="">顶级栏目</option> {capture name='me'} {$cate['cname']} {/capture} {get_cates val=$smarty.capture.me} <option value="field.id" selected>field.cname</option> {/get_cates} </select>
翻译
搜索
复制
标签:tmp,category,自定义,val,get,下拉,cates,str,select From: https://www.cnblogs.com/haokan/p/18242435