thinkPHP ページング関数の詳細な図による説明
この記事では主に thinkPHP のページング機能を紹介し、製品モデルに基づいてページング機能を実装するための thinkPHP の関連操作テクニックを完全な例の形で分析します。この記事では、thinkPHP のページング機能について説明しています。参考として、次のように全員と共有します。
interface ServiceInterFace:
<?php /** * InterFaceService * @author yhd */ namespace Red; interface ServiceInterFace { /** * 实例化当前类 */ public static function getInstance(); }
StaticService Static Service Class:
<?php /** * 静态服务类 * StaticService * @author yhd */ namespace Red; class StaticService{ protected static $data; /** * 设置静态数据 * @param string $key key * @param mixed $data data * @return mixed */ public static function setData($key,$data){ self::$data[$key] = $data; return self::$data[$key]; } /** * 通过引用使用静态数据 * @param string $key key * @return mixed */ public static function & getData($key){ if(!isset(self::$data[$key])){ self::$data[$key] = null; } return self::$data[$key]; } /** * 缓存实例化过的对象 * @param string $name 类名 * @return 对象 */ public static function getInstance($name){ $key = 'service_@_'.$name; $model = &self::getData($key); if($model === null){ $model = new $name(); } return $model; } /** * html转义过滤 * @param mixed $input 输入 * @return mixed */ public static function htmlFilter($input){ if(is_array($input)) { foreach($input as & $row) { $row = self::htmlFilter($row); } } else { if(!get_magic_quotes_gpc()) { $input = addslashes($input); } $input = htmlspecialchars($input); } return $input; } }
abstract AbProduct Abstract Product Management Class:
<?php /** * 抽象商品管理类 * AbProduct.class.php * @lastmodify 2015-8-17 * @author yhd */ namespace Red\Product; abstract class AbProduct{ public $errorNum; /* *返回错误信息 *@param $errorNum 错误代码 */ public function GetStatus(){ $errorNum = $this->errorNum; switch($errorNum){ case 0: $data['status'] = 0; $data['message'] = '收藏成功'; break; case 1: $data['status'] = 1; $data['message'] = '收藏失败'; break; case 2: $data['status'] = 2; $data['message'] = '已收藏'; break; case 3: $data['status'] = 3; $data['message'] = '未登陆'; break; case 4: $data['status'] = 4; $data['message'] = '缺少参数'; break; default: $data['status'] = 200; $data['message'] = '未知错误'; } return $data; }
メンバーモデルメンバーモデル:
<?php /** * 会员模型 * MemberModel.class.php * @copyright (C) 2014-2015 red * @license http://www.red.com/ * @lastmodify 2015-8-17 * @author yhd */ namespace Red\Passport\Models; use Think\Model; use Red\ServiceInterFace; use Red\StaticService; class MemberModel extends Model implements ServiceInterFace{ protected $userId; protected $error; protected function _initialize(){ $this->userId = getUserInfo(0); } /** * 实例化本类 * @return MemberModel */ public static function getInstance() { return StaticService::getInstance(__CLASS__); } /** * 获取登录用户信息 * @param string $data 查询条件 * @return array */ public function getUser($data = '') { if(empty($data)){ return $this->where("id=".$this->userId)->find(); }else{ return $this->field($data)->where("id=".$this->userId)->find(); } } /** * 修改用户信息 * @param array $data * @param array $where 查询条件 */ public function editUserInfo($data, $where = '') { if( $this->_before_check($data) === false ){ return $this->error['msg']; } if(!empty($where) && is_array($where)){ $condition[ $where[0] ] = array('eq', $where[1]); return $this->where($condition)->save($data); } return $this->where("id=".$this->userId)->save($data); } /** * 获取用户信息 * @param string $data 用户名 * return array() */ public function checkUserInfo($str, $field = ''){ //注册类型 $info = CheckType($str); $condition[$info] = array('eq',$str); if(!empty($field)){ return $this->field($field)->where($condition)->find(); } return $this->where($condition)->find(); } /** * 获取用户信息 * @param array $data 用户名 * return array() */ public function getAccount($data){ //注册类型 $info = CheckType($data); $condition['id'] = array('eq',$this->userId); $condition[$info] = array('eq',$data); return $this->where($condition)->find(); } /** * 修改用户密码 * @param array $data['id']用户ID * @param $data['passWord']用户密码 * return true or false */ public function upUserPassById($data){ $condition['id'] = array('eq',$data['id']); $status = $this->where($condition)->save(array("password"=>md5($data['password']))); if($status){ return TRUE; }else { return FALSE; } } /** * 校验用户的账号或者密码是否正确 * @param $data['username'] 用户名 * @param $data['password'] 密码 * return true or false */ public function checkUserPasswd($data= array()){ $type = CheckType($data['username']); $condition[$type] = array('eq',$data['username']); $condition['password'] = array('eq',md5($data['password'])); return $this->where($condition)->find(); } /** * 网页登录校验token * @param token string * return bool */ public function checkToken($token){ return $this->autoCheckToken($token); } /** * 后台封号/解封 * param int $user_id */ public function changeStatus($data){ if($this->save($data)){ return true; }else{ return false; } } protected function _before_check(&$data){ if(isset($data['username']) && empty($data['username'])){ $this->error['msg'] = '请输入用户名'; return false; } if(isset($data['nickname']) && empty($data['nickname'])){ $this->error['msg'] = '请输入昵称'; return false; } if(isset($data['realname']) && empty($data['realname'])){ $this->error['msg'] = '请输入真名'; return false; } if(isset($data['email']) && empty($data['email'])){ $this->error['msg'] = '请输入邮箱'; return false; } if(isset($data['mobile']) && empty($data['mobile'])){ $this->error['msg'] = '请输入手机号码'; return false; } if(isset($data['password']) && empty($data['password'])){ $this->error['msg'] = '请输入密码'; return false; } if(isset($data['headimg']) && empty($data['headimg'])){ $this->error['msg'] = '请上传头像'; return false; } return true; } }
ProductModel 製品モデル:
<?php /** * 商品模型 * ProductModel.class.php * @lastmodify 2015-8-17 * @author yhd */ namespace Red\Product\Models; use Think\Model; use Red\ServiceInterFace; use Red\StaticService; class ProductModel extends Model implements ServiceInterFace{ /** * 实例化本类 * @return ProductModel */ public static function getInstance() { return StaticService::getInstance(__CLASS__); } /** * 单个商品 * @param string $id * @param integer $status 状态 1:有效 2:无效 * @param integer $onsale 是否上架 1:是 2:否 * @return array 一维数组 */ public function getProOne($id, $status = 1 , $onsale = 1){ $condition['onsale'] = array('eq', $onsale); //是否上架 $condition['status'] = array('eq', $status); //状态 $condition['id'] = array('eq',$id); return $this->where($condition)->find(); } /** * 商品列表 * @param string $limit 查询条数 * @param array $data 查询条件 * @return array 二维数组 */ public function getProList($data = ''){ $condition['onsale'] = array('eq', $data['onsale']); //是否上架 $condition['status'] = array('eq', $data['status']); //状态 $condition['type'] = array('eq', $data['type']); //分类 if(isset($data['limit']) && isset($data['order']) ){ $return =$this->where($condition)->limit($data['limit'])->order($data['order'])->select(); }else{ $return =$this->where($condition)->select(); } return $return; } /** * 添加商品 * @param array $data * @return int */ public function addProduct($data){ return $this->add($data); } /** * 删除商品 * */ public function delProduct($id){ $condition['id'] = array('eq', $id); return $this->where($condition)->delete(); } /** * 修改商品 * @param string|int $id * @param array $data * @return */ public function editProdcut($id, $data){ $condition['id'] = array('eq', $id); return $this->where($condition)->save($data); } public function getProductInfo($product){ if(empty($product) || !isset($product['product_id'])){ return array(); } $info = $this->getProOne($product['product_id']); $product['name'] = $info['name']; $product['store_id'] = $info['store_id']; $product['price'] = $info['price']; $product['m_price'] = $info['m_price']; return $product; } }
ProductManage 製品管理クラス:
<?php namespace User\Controller; use Red\Product\ProductManage; class FavoriteController extends AuthController { public function index($page=1){ $limit=1; $list = ProductManage::getInstance()->getCollectList($page,$limit); $showpage = create_pager_html($list['total'],$page,$limit); $this->assign(get_defined_vars()); $this->display(); } public function cancelCollect(){ $ids = field('ids'); $return = ProductManage::getInstance()->cancelProductCollect($ids); exit(json_encode($return)); } }
functions.php ページネーション関数:
rrreええ関連推奨事項: SQLite に基づいて
ページネーション関数を実装する
PHP+Ajaxメソッドでリフレッシュなしを実装するページネーション関数
thinkPHPメソッドでマルチテーブルクエリと
以上がthinkPHP ページング関数の詳細な図による説明の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック









PHP 8.4 では、いくつかの新機能、セキュリティの改善、パフォーマンスの改善が行われ、かなりの量の機能の非推奨と削除が行われています。 このガイドでは、Ubuntu、Debian、またはその派生版に PHP 8.4 をインストールする方法、または PHP 8.4 にアップグレードする方法について説明します。

Visual Studio Code (VS Code とも呼ばれる) は、すべての主要なオペレーティング システムで利用できる無料のソース コード エディター (統合開発環境 (IDE)) です。 多くのプログラミング言語の拡張機能の大規模なコレクションを備えた VS Code は、

JWTは、JSONに基づくオープン標準であり、主にアイデンティティ認証と情報交換のために、当事者間で情報を安全に送信するために使用されます。 1。JWTは、ヘッダー、ペイロード、署名の3つの部分で構成されています。 2。JWTの実用的な原則には、JWTの生成、JWTの検証、ペイロードの解析という3つのステップが含まれます。 3. PHPでの認証にJWTを使用する場合、JWTを生成および検証でき、ユーザーの役割と許可情報を高度な使用に含めることができます。 4.一般的なエラーには、署名検証障害、トークンの有効期限、およびペイロードが大きくなります。デバッグスキルには、デバッグツールの使用とロギングが含まれます。 5.パフォーマンスの最適化とベストプラクティスには、適切な署名アルゴリズムの使用、有効期間を合理的に設定することが含まれます。

このチュートリアルでは、PHPを使用してXMLドキュメントを効率的に処理する方法を示しています。 XML(拡張可能なマークアップ言語)は、人間の読みやすさとマシン解析の両方に合わせて設計された多用途のテキストベースのマークアップ言語です。一般的にデータストレージに使用されます

文字列は、文字、数字、シンボルを含む一連の文字です。このチュートリアルでは、さまざまな方法を使用してPHPの特定の文字列内の母音の数を計算する方法を学びます。英語の母音は、a、e、i、o、u、そしてそれらは大文字または小文字である可能性があります。 母音とは何ですか? 母音は、特定の発音を表すアルファベットのある文字です。大文字と小文字など、英語には5つの母音があります。 a、e、i、o、u 例1 入力:string = "tutorialspoint" 出力:6 説明する 文字列「TutorialSpoint」の母音は、u、o、i、a、o、iです。合計で6元があります

静的結合(静的::) PHPで後期静的結合(LSB)を実装し、クラスを定義するのではなく、静的コンテキストで呼び出しクラスを参照できるようにします。 1)解析プロセスは実行時に実行されます。2)継承関係のコールクラスを検索します。3)パフォーマンスオーバーヘッドをもたらす可能性があります。

PHPの魔法の方法は何ですか? PHPの魔法の方法には次のものが含まれます。1。\ _ \ _コンストラクト、オブジェクトの初期化に使用されます。 2。\ _ \ _リソースのクリーンアップに使用される破壊。 3。\ _ \ _呼び出し、存在しないメソッド呼び出しを処理します。 4。\ _ \ _ get、dynamic属性アクセスを実装します。 5。\ _ \ _セット、動的属性設定を実装します。これらの方法は、特定の状況で自動的に呼び出され、コードの柔軟性と効率を向上させます。

ThinkPhp6ルーティングパラメーターは、中国と完全な買収で処理されます。 ThinkPhp6フレームワークでは、特殊文字(中国語や句読点など)を含むURLパラメーターがしばしば処理されます...
