本文整理匯總了PHP中think\Model類的典型用法代碼示例。如果您正苦於以下問題:PHP Model類的具體用法?PHP Model怎麽用?PHP Model使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Model類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getFriend
public function getFriend($userid)
{
$sql = "select u.name,u.id from __USERS__ as u,(select user2 from __FRIEND__ where user1 = {$userid} \r\n UNION select user1 from __FRIEND__ where user2 = {$userid}) as f where u.id = f.user2";
$model = new Model();
$data = $model->query($sql);
return $data;
}
示例2: header_city
public function header_city()
{
$city1 = new \Think\Model();
$sql = "select r.* from __PREFIX__store_shipping_region as ssr left join __PREFIX__region as r on ssr.city=r.region_id where ssr.city>0 group by ssr.city";
$rs = $city1->query($sql);
var_dump($rs);
}
示例3: listView
public function listView($cate)
{
$cate_atc = M('cate_atc');
$count = $cate_atc->where(['status' => 1, 'cate' => $cate])->count();
$Page = new \Think\Page($count, 16);
// 實例化分頁類 傳入總記錄數和每頁顯示的記錄數
$show = $Page->show();
// 分頁顯示輸出
$list = $cate_atc->where(['cate' => $cate])->order('createtime')->limit($Page->firstRow . ',' . $Page->listRows)->select();
$model = new Model();
foreach ($list as $k => $v) {
$modelInfo = get_model_info($v['model_id']);
//獲每條數據的模型信息
//echo $modelInfo['identity'];
$raw = $model->query("select author from {$modelInfo['identity']} where id = {$v['atc_id']}");
$list[$k]['author'] = $raw[0]['author'];
$d = strtotime($v['createtime']);
$list[$k]['createtime'] = '<div>' . date("Y/m/d", $d) . '</div>' . '<div>' . date("H:i:s", $d) . '</div>';
//編輯時間格式
}
//var_dump($show);
/* $Page->setConfig('f_decorate','<li>');
$Page->setConfig('b_decorate','</li>');*/
$this->assign('page', $show);
$this->assign('list', $list);
$this->assign('model_list', get_cate_Model($cate));
//$this->assign("cate_id",1);
$this->assign("cate", $cate);
$this->display();
}
示例4: loginCheck
/**
* 登錄驗證
* @param $loginArr
* @return $arr
*/
public function loginCheck($loginArr)
{
$User = new Model('user');
$array['US_name'] = $loginArr['US_name'];
//設置用戶等級為管理員
$array['Us_level'] = 2;
$result = $User->where($array)->select();
$arr = array();
$arr['status'] = 0;
if ($result != null && count($result) == 1) {
if (strcmp(md5($loginArr['password']), $result[0]['password']) == 0) {
//登陸成功
$arr['status'] = 1;
$arr['content'] = '驗證成功!';
return $arr;
} else {
//登陸失敗(密碼錯誤)
$arr['content'] = '密碼錯誤!';
return $arr;
}
} else {
$arr['content'] = '用戶名不存在!';
return $arr;
}
}
示例5: getCitiesByProvince
public function getCitiesByProvince($province)
{
$sql = "select a.city as city from t_cities a, t_provinces b\r\n where b.province like '" . $province . "%' and b.provinceid = a.provinceid";
$m = new \Think\Model();
$result = $m->query($sql);
return $result;
}
示例6: detail
public function detail()
{
$Form = new Model();
$result = $Form->query('select admin_articles.*, admin_nickname from admin_articles
inner join admin_personal on admin_articles.admin_id = admin_personal.admin_id
where article_id="%s"', $_GET['p']);
if ($result) {
$result[0]['article_type'] = C('MODULE_CODE')[$result[0]['article_type']];
//dump($result[0]);
if ($result[0]['article_about'] == C(PROJECT_CODE)) {
$object = $Form->query('select project_name as name, project_logo as portrait from project_info
where project_id = "%s"', $result[0]['article_object']);
//dump($object);
$this->obj = $object[0];
} else {
if ($result[0]['article_about'] == C(INVESTOR_CODE)) {
$object = $Form->query('select name, portrait from investor_personal
where user_id = "%s"', $result[0]['article_object']);
//dump($object);
$this->obj = $object[0];
} else {
if ($result[0]['article_about'] == C(INNOVATOR_CODE)) {
$object = $Form->query('select name, portrait from entrepreneur_personal
where user_id = "%s"', $result[0]['article_object']);
//dump($object);
$this->obj = $object[0];
}
}
}
$this->p = $result[0];
}
$update = $Form->execute('update admin_articles set article_visits=%d where article_id="%s"', $result[0]['article_visits'] + 1, $_GET['p']);
$this->display();
}
示例7: doLogin
public function doLogin()
{
// 參數非法,則重新登錄
if (empty($_POST["name"]) || empty($_POST["password"]) || empty($_POST["code"])) {
$this->ajaxReturn(array("content" => null, "info" => "輸入不能為空", "status" => false));
exit(1);
}
//驗證碼生成
$code = $_POST['code'];
$Ver = new CodeController();
if (!$Ver->check_verify($code)) {
// 驗證碼錯誤
$this->ajaxReturn(array("content" => null, "info" => "驗證碼錯誤", "status" => false));
$this->error("驗證碼錯誤", "index");
exit(1);
}
//獲取用戶名
$username = $_POST['name'];
//獲取密碼
$password = $_POST["password"];
//創建systemmanager 的Model
$m = new Model("systemmanager");
//$res = $m->field ( "sys_password,sys_id" )->where ( "sys_username='{$username}'" )->select ();
$res = $m->field("sys_password,sys_id")->where("sys_username='%s'", $username)->select();
// 防注入 查找
if ($res[0]['sys_password'] == md5($password)) {
//若賬號和密碼都正確則登錄成功,並存入相關session
$_SESSION['systemmanager'] = $username;
$_SESSION['sys_id'] = $res[0]['sys_id'];
$this->ajaxReturn(array("content" => null, "info" => "登錄成功!", "status" => true));
}
//用戶名或者密碼錯誤,則登錄失敗
$this->ajaxReturn(array("content" => null, "info" => "用戶名或者密碼錯誤!", "status" => false));
}
示例8: getCategory
function getCategory()
{
/* $data['slug'] <> 'uncategorized';
return $this->where($data)->select();*/
$Model = new Model();
return $Model->query("select * from wp_terms where wp_terms.slug <> 'uncategorized'");
}
示例9: checkVerfiyCode
function checkVerfiyCode()
{
$param = json_decode(file_get_contents('php://input'), true);
$phone = $param['phone'];
$verfiycode = $param['verfiycode'];
if (empty($phone)) {
err_ret(-205, 'lack of param', '缺少參數');
}
if (empty($verfiycode)) {
err_ret(-205, 'lack of param', '缺少參數');
}
//萬能驗證碼
if ($verfiycode == '0228') {
http_ret(0, 'verify code is correct', '驗證碼正確');
}
$model = new Model('verify_tmp');
$condition['phone'] = $phone;
$condition['verifycode'] = $verfiycode;
$result = $model->where($condition)->select();
if (count($result) <= 0) {
err_ret(-307, 'verfiy code is incorrect', '驗證碼不正確');
}
$time = time() - $result[0]['gen_time'];
if ($time > 5 * 60) {
err_ret(-308, 'verify code is invalid', '驗證碼已過期');
}
if ($verfiycode == $result[0]['verifycode']) {
http_ret(0, 'verify code is correct', '驗證碼正確');
} else {
err_ret(-307, 'verfiy code is incorrect', '驗證碼不正確');
}
}
示例10: login
public function login()
{
$Form = new Model();
$user = $Form->query("select * from admin_personal where admin_id = '%s'", $_POST['loginuser']);
//echo json_encode($user[0]);
if ($user[0]['admin_pwd'] === $_POST['loginpwd']) {
$_SESSION['userid'] = $user[0]['admin_id'];
//session(array('name'=>'userid','expire'=>2),$user[0]['admin_id']);
$_SESSION['usertype'] = $user[0]['admin_type'];
if ($_SESSION['usertype'] == 1) {
echo 201;
} else {
if ($_SESSION['usertype'] == 2) {
echo 202;
} else {
if ($_SESSION['usertype'] == 3) {
echo 203;
} else {
echo 404;
}
}
}
} else {
echo 409;
}
}
示例11: check
public function check($para)
{
$user = $para['user'];
$type = $para['type'];
$pwd = md5($para['pwd']);
$vcode = $para['verifycode'];
//首先驗證驗證碼
if ($this->check_verify($vcode)) {
//驗證賬號密碼
switch ($type) {
case '3':
$tb = 'user_admin';
$tb2 = 'user_admin';
break;
case '2':
$tb = 'user_teacher_pwd';
$tb2 = 'user_teacher';
break;
case '1':
$tb = 'user_student_pwd';
$tb2 = 'user_student';
}
$Model = new \Think\Model();
$sql = "select * from {$tb2} B left join {$tb} A on A.user=B.user where A.user='{$user}' and A.pwd='{$pwd}' and B.status=1";
//var_dump($sql);
if (count($Model->query($sql))) {
return 1;
} else {
return 0;
}
} else {
return -1;
}
}
示例12: db
public function db()
{
$m = new Model('Post');
$list = $m->select();
dump($list);
echo $m->getLastSql();
}
示例13: myUpdate
public function myUpdate($data)
{
$id = (int) $data['id'];
if ($id <= 0) {
$this->error = '請先選擇要更新的分類';
return false;
}
unset($data['id']);
if ($id == $data['parent_id']) {
$data['parent_id'] = 0;
}
//所屬分類等於自己時, 更正為頂級分類
//驗證數據
if (false === $this->create($data, self::MODEL_UPDATE)) {
return false;
}
//驗證 parent_id合法性
if ($this->parent_id > 0) {
$model = new Model('Category');
//避免 model 混淆
$parent = $model->find($this->parent_id);
if (false === $parent || empty($parent)) {
$this->error = '父級分類不存在';
return false;
}
$orginfo = $model->find($id);
if ($orginfo['store_id'] != $parent['store_id']) {
$this->error = '父級分類不存在當前店鋪';
return false;
}
}
return $this->where('`id`=' . $id)->save();
}
示例14: index
/**
* 列表顯示
*/
public function index()
{
if (!IS_AJAX) {
$this->error(L('_ERROR_ACTION_'));
}
$Model = new Model();
$islang = $Model->query('Describe __' . strtoupper(CONTROLLER_NAME) . '__ lang');
if ($islang[0]['field'] == 'lang') {
if (I('get.lang')) {
$wl = 'lang=\'' . I('get.lang') . '\'';
} elseif ($this->clang) {
$wl = 'lang=\'' . $this->clang . '\'';
} else {
$wl = 'lang=\'' . LANG_SET . '\'';
}
} else {
$wl = '1';
}
$isorder = $Model->query('Describe __' . strtoupper(CONTROLLER_NAME) . '__ listorder');
$ol = $isorder == 'listorder' ? 'listorder,' : '';
$name = M(CONTROLLER_NAME);
$list = $name->where($wl)->order($ol, 'id')->select();
$this->assign('list', $list);
$this->display();
}
示例15: comment
public function comment($id)
{
$model = new Model('Article');
$article = $model->find(array('articleId' => $id));
if (empty($article)) {
$this->error('文章不存在');
}
$key = get_client_ip() . '-view-article-' . $id;
$cache = S($key);
if (!empty($cache)) {
$this->error('評論間隔必須大於1分鍾');
}
$nickname = I('nickname');
$content = I('content');
if (empty($nickname)) {
$this->error('昵稱不能為空');
}
if (empty($content)) {
$this->error('評論內容不能為空');
}
$data = array('nickname' => $nickname, 'content' => $content, 'createdAt' => time(), 'createdIp' => get_client_ip(), 'articleId' => $id);
$commentModel = new Model('Comment');
if (!$commentModel->data($data)->add()) {
$this->error('評論失敗');
}
S($key, 1, 60);
$data['createdAt'] = date('m-d H:i', $data['createdAt']);
$this->ajaxReturn($data);
}