本文整理汇总了PHP中think\Model::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::select方法的具体用法?PHP Model::select怎么用?PHP Model::select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类think\Model
的用法示例。
在下文中一共展示了Model::select方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getList
public function getList($wheres = array())
{
//查询条件为数据状态大于 -1 的数据
if (!empty($wheres)) {
$wheres['status'] = array('gt', -1);
} else {
$wheres['status'] = array('gt', -1);
}
//获取分页的工具条
$totalRows = $this->where($wheres)->count();
//准备数数据状态大于-1的总条数
$listRows = 2;
//确定每一页显示的数据条数
//实例化分页工具条的对像
$page = new Page($totalRows, $listRows);
//>>判断是否要修改主题
if ($totalRows > $listRows) {
$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
}
//存储分页的条件
$pageHtml = $page->show();
//>>每一页的数据删除完之后显示这页数据的上一页
//查询出每一页需要显示的数据
$this->limit($page->firstRow, $page->listRows)->where($wheres);
$rows = parent::select();
return array('rows' => $rows, 'pageHtml' => $pageHtml);
}
示例2: index
public function index()
{
$model = new Model('Category');
$list = $model->select();
$this->assign('list', $list);
$this->display();
}
示例3: db
public function db()
{
$m = new Model('Post');
$list = $m->select();
dump($list);
echo $m->getLastSql();
}
示例4: getActionList
function getActionList()
{
header('Access-Control-Allow-Origin:*');
//跨域
header("Content-type: text/html; charset=utf-8");
$param = json_decode(file_get_contents('php://input'), true);
$token = $param['xtoken'];
//init_verify_token($token);
$t_action = C('T_ACTION');
$model = new Model($t_action);
$result = $model->select();
$data["errno"] = 0;
$data["action_list"] = $result;
echo json_encode($data);
}
示例5: getUsers
/**
* 获取用户
* @return mixed
*/
public function getUsers()
{
$User = new Model('user');
return $User->select();
}
示例6: testModel
public function testModel()
{
$config = array('db_type' => 'mysql', 'db_user' => 'root', 'db_pwd' => 'root123', 'db_host' => 'localhost', 'db_port' => '3306', 'db_name' => 'test');
$modle = new Model('user', '', $config);
var_dump($modle->select());
}
示例7: select
/**
* 使用相套sql语句,代替视图
* */
public function select($options = array())
{
if (!empty($this->viewTableName)) {
$orgTableName = $options["table"];
$options["table"] = $this->viewTableName;
}
//
$res = parent::select($options);
$options["table"] = $orgTableName;
return $res;
}
示例8: getCategories
public function getCategories()
{
$Category = new Model('category');
return $Category->select();
}
示例9: select
/**
* 重写select方法 以支持associate和sqlOptions
*
* 如果传入了['hy'=>true]则模型SQL基础配置生效!
* 如果调用了associate连贯操作,则会执行框架的连表查询
*
* @param array $options 表达式参数
* @return array
*/
public function select($options = array())
{
if (!($arr = $this->isCallHyFunc($options))) {
return parent::select($options);
}
list($hy, $associate) = $arr;
if ($associate) {
$associate = array_merge($hy ? $this->sqlOptions['associate'] : array(), $this->_associate);
}
// 收集table
if ($associate) {
$this->table(array($this->getTableName() => self::HYP));
}
// 收集limit
if ($hy && !$this->options['limit']) {
$this->limit($this->pageOptions['limit']);
}
// 收集order
if ($order = $this->options['order'] ?: ($hy ? $this->pageOptions['order'] : null)) {
// 排序字段自动加表别名以避免冲突
if ($associate && is_string($order)) {
$order = $this->fieldPre($order, self::HYP);
}
$this->options['order'] = $order;
}
// 收集field
if ($associate && ($field = $this->options['field'] ?: ($hy ? $this->sqlOptions['field'] : array()))) {
// 防止多表中字段冲突
if (is_string($field)) {
$field = $this->fieldPre($field, self::HYP);
if (is_string($field)) {
$field = array($field);
}
}
if (is_array($field)) {
foreach ($field as $k => $v) {
if (is_numeric($k)) {
$field[$k] = $this->fieldPre($field[$k], self::HYP);
}
}
}
} else {
$field = $this->getAllFields($field, $associate ? self::HYP : '');
}
// 收集 where - sqlOptions
if ($hy) {
// 拷贝副本,不影响下次使用sqlOptions['where']
$this->sqlOptions['_where'] = $this->sqlOptions['where'];
// 收集where - search
if ($hy && method_exists($this, 'searchMap')) {
$this->searchMap();
}
if ($this->options['where']['_string']) {
$this->addMap($this->options['where']['_string']);
unset($this->options['where']['_string']);
}
// 整合到TP
$this->where($this->sqlOptions['_where']);
}
// where条件中的字段避免冲突
if ($associate && $this->options['where']) {
$arr = array();
foreach ($this->options['where'] as $k => $v) {
if (0 === strpos($k, '_')) {
continue;
}
$arr[$this->fieldPre($k, self::HYP)] = $v;
unset($this->options['where'][$k]);
}
if ($arr) {
$this->where($arr);
}
}
// 连表处理
if (is_array($associate) && $associate) {
// 当前表默认别名 HYP常量
$join = array();
foreach ($associate as $v) {
$asc = explode('|', $v);
// 0=>关联表名(支持别名),1=>当前表外键,2=>关联表主键,3=>要从关联表取出的字段(多个以“,”分隔),4=>限制条件,5=>join类型(默认inner)
preg_match('/([\\w\\.\\-\\(\\)]+)\\s*(AS)*\\s*([\\w\\-]*)/i', $asc[0], $m);
$asc[0] = $m[3] ?: $m[1];
if ($asc[4]) {
$pre = $asc[0] . '.';
$asc[4] = preg_replace_callback('/`([\\w\\-]+)`/', function ($m1) use($pre) {
if ($m1[1]) {
return $pre . $m1[1];
}
}, $asc[4]);
}
$asc[5] = $asc[5] ? strtoupper($asc[5]) : 'INNER';
//.........这里部分代码省略.........
示例10: addManyDayCourse
function addManyDayCourse()
{
header('Access-Control-Allow-Origin:*');
//跨域
header("Content-type: text/html; charset=utf-8");
$param = json_decode(file_get_contents('php://input'), true);
/* $str = '{
"xtoken":"35dsakfsdjfcvjdsajfkdsf234",
"coachid":45,
"uid":999,
"pid":41,
"course_list":[
{
"course_time":32435435,
"action_list":[
{
"actionid":177,
"group":3,
"count":20,
"order":1,
"type":1,
"duration":34
},
{
"actionid":188,
"group":3,
"count":20,
"order":1,
"type":2,
"duration":54
}]
},
{
"course_time":32438935,
"action_list":[
{
"actionid":199,
"group":3,
"count":20,
"order":1,
"type":1,
"duration":34
},
{
"actionid":166,
"group":3,
"count":20,
"order":1,
"type":2,
"duration":54
}]
}]
}';*/
// $param = json_decode($str,true);
$token = $param['xtoken'];
init_verify_token($token);
$uid = $param['uid'];
$pid = $param['pid'];
$coachid = $param['coachid'];
if (!isset($uid) || !isset($pid) || !isset($coachid)) {
err_ret(-205, 'lack of param', '缺少参数');
}
$course_list = $param['course_list'];
//找到开始时间和结束时间
$begin_time = $course_list[0]['course_time'];
$end_time = $course_list[0]['course_time'];
for ($i = 0; $i < count($course_list); $i++) {
if ($course_list[$i]['course_time'] <= $begin_time) {
$begin_time = $course_list[$i]['course_time'];
}
if ($course_list[$i]['course_time'] >= $end_time) {
$end_time = $course_list[$i]['course_time'];
}
}
//课程id
$model_course_record = new Model('course_record');
$cur_courseid = $model_course_record->max('courseid') + 1;
//获取 pay_time
$model_my_plan = new Model('my_plan');
$condition['uid'] = $uid;
$condition['pid'] = $pid;
$condition['coachid'] = $coachid;
$condition['courseid'] = 0;
$result_pay_time = $model_my_plan->select();
$pay_time = $result_pay_time[0]['pay_time'];
$model_my_plan->where($condition)->delete();
//删除记录为courseid=0的
for ($i = 0; $i < count($course_list); $i++) {
//添加课程记录
$action_list = $course_list[$i]['action_list'];
for ($j = 0; $j < count($action_list); $j++) {
$action_list[$j]['courseid'] = $cur_courseid;
$model_course_record->add($action_list[$j]);
}
//把相应的课程记录添加到my_plan
unset($data_my_plan);
$data_my_plan['uid'] = $uid;
$data_my_plan['pid'] = $pid;
$data_my_plan['coachid'] = $coachid;
$data_my_plan['courseid'] = $cur_courseid;
//.........这里部分代码省略.........
示例11: getSlides
public function getSlides()
{
$Slide = new Model('slide');
return $Slide->select();
}