コード例 #1
0
ファイル: function.getall.php プロジェクト: superwmh/swoole
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 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 fetch_select($dname, $params)
 {
     $select = new SelectDB($this->swoole->db);
     $select->from($dname);
     $select->put($params);
     return $select->getall();
 }
コード例 #3
0
ファイル: block.select.php プロジェクト: superwmh/swoole
function smarty_block_select($params, $body, &$smarty)
{
    if (is_null($body)) {
        return;
    }
    global $php;
    $select = new SelectDB($php->db);
    $select->put($params);
    return SwooleTemplate::parse_loop($select->getall(), $body);
}
コード例 #4
0
ファイル: function.getone.php プロジェクト: superwmh/swoole
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 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']];
}
コード例 #5
0
ファイル: Model.php プロジェクト: ninjanero/framework
 /**
  * 获取一个数据列表,功能类似于gets,此方法仅用于SiaoCMS,不作为同样类库的方法
  * @param $params
  * @param $get
  * @return array
  */
 function getList(&$params, $get = 'data')
 {
     $selectdb = new SelectDB($this->db);
     $selectdb->from($this->table);
     $selectdb->select($this->select);
     $selectdb->limit(isset($params['row']) ? $params['row'] : 10);
     unset($params['row']);
     $selectdb->order(isset($params['order']) ? $params['order'] : $this->primary . ' desc');
     unset($params['order']);
     if (isset($params['typeid'])) {
         $selectdb->where($this->foreignkey . '=' . $params['typeid']);
         unset($params['typeid']);
     }
     $selectdb->put($params);
     if (array_key_exists('page', $params)) {
         $selectdb->paging();
         global $php;
         $php->env['page'] = $params['page'];
         $php->env['start'] = 10 * intval($params['page'] / 10);
         if ($selectdb->pages > 10 and $params['page'] < $php->env['start']) {
             $php->env['more'] = 1;
         }
         $php->env['end'] = $selectdb->pages - $php->env['start'];
         $php->env['pages'] = $selectdb->pages;
         $php->env['pagesize'] = $selectdb->page_size;
         $php->env['num'] = $selectdb->num;
     }
     if ($get === 'data') {
         return $selectdb->getall();
     } elseif ($get === 'sql') {
         return $selectdb->getsql();
     }
 }
コード例 #6
0
 /**
  * Compile {db ...} tag
  * it htf write
  *
  * @param string $tag_args
  * @return string
  */
 function _compile_db_start($tag_args)
 {
     $attrs = $this->_parse_attrs($tag_args);
     foreach ($attrs as &$attr) {
         $attr = str_replace("'", '', $attr);
     }
     if (empty($attrs['from'])) {
         $this->_syntax_error("missing db_select table name", E_USER_ERROR, __FILE__, __LINE__);
     }
     if (!array_key_exists('_name', $attrs)) {
         $attrs['_name'] = 'records';
     }
     $output = "<?php \n";
     if ($this->db == '') {
         global $php;
         $php->autoload('db');
         $this->db = $php->db;
         $output .= "global \$php;\n";
     }
     $select = new SelectDB($this->db);
     $select->call_by = 'smarty';
     //		if(!array_key_exists('limit',$attrs) and !array_key_exists('page',$attrs)) $attrs['limit']=10;
     $attrs['select'] = str_replace('"', '', $attrs['select']);
     $attrs['select'] = str_replace("'", '', $attrs['select']);
     $select->put($attrs);
     $output .= "\$sql=\"" . $select->getsql() . "\";\n";
     $output .= "\$this->_tpl_vars['{$attrs['_name']}']=\$php->db->query(\$sql)->fetchall();\n";
     $output .= '$' . $attrs['_name'] . '_count = count($this->_tpl_vars["' . $attrs['_name'] . '"]);' . "\n";
     $output .= 'for($' . $attrs['_name'] . '_i=0;$' . $attrs['_name'] . '_i<$' . $attrs['_name'] . '_count;$' . $attrs['_name'] . '_i++):' . "\n";
     $output .= '$this->_records["' . $attrs['_name'] . '"]["index"]=$' . $attrs['_name'] . '_i;' . "\n";
     $output .= '$this->_records["' . $attrs['_name'] . '"]["first"]= $' . $attrs['_name'] . '_i==0;' . "\n";
     $output .= '$this->_records["' . $attrs['_name'] . '"]["last"]= $' . $attrs['_name'] . '_i==($' . $attrs['_name'] . '_count-1);' . "\n";
     $output .= '$this->_sections["' . $attrs['_name'] . '"]["index"]=$' . $attrs['_name'] . '_i;' . "\n";
     $output .= "?>\n";
     return $output;
 }
コード例 #7
0
 function proc_record($tag, $tag_head)
 {
     $param = self::parse_param($tag);
     $record_name = $param['_name'];
     $record_field = $param['_field'];
     if ($this->{$record_name} != false) {
         $record = $this->{$record_name};
     } else {
         $select = new SelectDB($this->db);
         $select->put($param);
         $record = $select->getone();
         $this->{$record_name} = $record;
     }
     $this->out_content .= $record[$record_field];
     $this->c_content = str_replace($tag_head, '', $this->c_content);
 }
コード例 #8
0
ファイル: CMS.model.php プロジェクト: superwmh/swoole
 function getPlot(&$attrs)
 {
     $select = new SelectDB($this->db);
     $select->call_by = 'smarty';
     $select->from(TABLE_PREFIX . '_plot');
     unset($attrs['get'], $attrs['name'], $attrs['key'], $attrs['func']);
     $select->put($attrs);
     return $select->getsql();
 }