示例#1
0
function smarty_function_getall($params, &$smarty)
{
    if (!isset($params['from'])) {
        echo 'No table name!';
        return false;
    }
    if (!isset($params['_name'])) {
        echo 'No record variable name!';
        return false;
    }
    global $php;
    $select = new Swoole\SelectDB($php->db);
    $select->call_by = 'func';
    if (!isset($params['order'])) {
        $params['order'] = 'id desc';
    }
    $select->put($params);
    if (isset($params['page'])) {
        $select->paging();
        $pager = $select->pager;
        $smarty->assign("pager", array('total' => $pager->total, 'render' => $pager->render()));
    }
    $records = $select->getall();
    $smarty->_tpl_vars[$params['_name']] = $records;
}
示例#2
0
function smarty_block_select($params, $body, &$smarty)
{
    if (is_null($body)) {
        return;
    }
    global $php;
    $select = new Swoole\SelectDB($php->db);
    $select->put($params);
    return SwooleTemplate::parse_loop($select->getall(), $body);
}
function smarty_function_getone($params, &$smarty)
{
    $record_name = $params['_name'];
    if (!array_key_exists($record_name, $smarty->_tpl_vars) or array_key_exists('_force', $params)) {
        global $php;
        $select = new Swoole\SelectDB($php->db);
        $select->call_by = 'func';
        $select->put($params);
        $record = $select->getone();
        $smarty->_tpl_vars[$record_name] = $record;
    }
    //if(array_key_exists('_field',$params)) return $smarty->_tpl_vars[$record_name][$params['_field']];
}