ci3+smarty模仿開發出dedecms標籤

哆啦啊梦發表於2024-05-31

1、建立塊函式

function smarty_block_b_info($arr, $content, $repeat)
{

if ($repeat) {
$ci = &get_instance();
$res = $ci->db->get('val', $arr['limit'])->result_array();

$str = '';
$tmp = $content;

foreach ($res as $k => $v) {
$rs = str_replace('field.id', $v['id'], $tmp);
$str .= str_replace('field.val', $v['val'], $rs);
}

return $str;
}
}

2、前端檢視呼叫塊函式

<body>
    <ul>
        {b_info limit=10}
        <li>
            <div>field.id</div><div>field.val</div>
        </li>
        {/b_info}
    </ul>
</body>

相關文章