thinkphpÔõôɨ³ýÌض¨Ãü¾ÝÏÔʾ
ÔÚʹÓÃthinkphp¿ò¼Ü¾ÙÐпª·¢Ê±£¬¾³£»áÐèҪɨ³ýÌض¨Ãü¾ÝÀ´¾ÙÐÐÏÔʾ£¬ÒÔÌá¸ß³ÌÐòµÄÖÊÁ¿ºÍЧÂÊ¡£±¾ÎĽ«ÏÈÈÝÔÚthinkphp¿ò¼ÜÏÂÔõÑùɨ³ýÌض¨Ãü¾Ý²¢¾ÙÐÐÏÔʾ¡£
Ò»Ñùƽ³£ÇéÐÎÏÂÎÒÃÇÐèҪɨ³ýijЩÌض¨µÄÊý¾ÝÀ´¾ÙÐÐÏÔʾ£¬ºÃ±È˵ÎÒÃÇÓÐÒ»¸öÓû§±í£¬ÆäÖÐÓÐÒ»ÁмͼÁËÓû§±»½ûÓõÄÇéÐΣ¬ÎÒÃÇÔÚ¾ÙÐÐÓû§ÁбíµÄÏÔʾʱ£¬¾Í²»Ï£Íû°ÑÒѾ±»½ûÓõÄÓû§ÏÔʾ³öÀ´¡£ÄÇôÔõÑù¿ìËÙʵÏÖÕâ¸ö¹¦Ð§ÄØ£¿
˼Ð÷¾ÍÊÇÔÚÊý¾ÝÅÌÎÊʱ¼ÓÉÏÒ»¸öɸѡÌõ¼þ£¬°ÑÊý¾ÝÖÐÇкÏÌõ¼þµÄ¹ýÂ˵ô¡£
ÔÚthinkphp¿ò¼ÜÏ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÄ£×ÓÅÌÎʵķ½·¨À´ÊµÏÖÕâ¸ö¹¦Ð§¡£Ê×ÏÈ£¬ÎÒÃÇÐèÒª½ç˵һ¸öÄ£×Ó£¬ÀýÈçUserModel¡£
<?php namespace app\model; use think\Model; class UserModel extends Model { // Ä£×Ó¶ÔÓ¦µÄÊý¾Ý±íÃû protected $table = 'user'; }
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂëÖУ¬ÎÒÃǽç˵ÁËÒ»¸öUserModelÄ£×Ó£¬¶ÔÓ¦µÄÊý¾Ý±íÃûΪuser¡£½ÓÏÂÀ´£¬ÎÒÃǾͿÉÒÔÔÚ¿ØÖÆÆ÷ÖÐŲÓøÃÄ£×Ó£¬²¢¼ÓÈë¹ýÂËÌõ¼þ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
<?php namespace app\controller; use app\model\UserModel; class UserController { public function userList() { // ½¨ÉèUserModel¹¤¾ß $userModel = new UserModel(); // ÅÌÎÊÌõ¼þ $where = [ 'is_disabled' => 0, // Ö»ÅÌÎÊδ½ûÓõÄÓû§ ]; // ÅÌÎÊÊý¾Ý $userList = $userModel->where($where)->select(); // ·µ»ØÊý¾Ý²¢äÖȾÊÓͼ return view('userList', ['userList' => $userList]); } }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëÖУ¬ÎÒÃÇÔÚÅÌÎÊÓû§Êý¾Ýʱ£¬¼ÓÈëÁËÒ»¸ö¹ýÂËÌõ¼þ£¬Ö»ÅÌÎÊδ½ûÓõÄÓû§(is_disabled = 0)£¬¹ýÂ˵ôÒѽûÓõÄÓû§¡£ÕâÑù£¬ÎÒÃǾͿÉÒÔɨ³ýÌض¨Ãü¾Ý²¢¾ÙÐÐÏÔʾÁË¡£
˼Ð÷ÕվɽÏÁ¿¼òÆӵģ¬µ«ÐèҪעÖصÄÊÇ£¬ÔÚÏÖʵ¿ª·¢ÖУ¬ÎÒÃÇÍùÍùÐèҪͬʱ˼Á¿¶àÖÖÇéÐΣ¬ÐèҪʹÓöà¸öÅÌÎÊÌõ¼þÀ´¹ýÂË¡£Õâʱ¿ÉÒÔ½ÓÄÉThinkPHPÄÚÖõÄÅÌÎʱí´ïʽÀ´×ÊÖúÍê³É¶àÌõ¼þÅÌÎÊ¡£
ÀýÈ磬ÎÒÃÇÏ£ÍûÅÌÎÊÄêËêÔÚ18ËêÒÔÉÏ¡¢ÐÔ±ðΪŮÐÔµÄÓû§£¬ÎÒÃÇ¿ÉÒÔÕâÑùд£º
$where = [ 'age' => ['egt', 18], 'gender' => 'female', ]; $userList = $userModel->where($where)->select();
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇʹÓÃÁËÅÌÎʱí´ïʽegtÀ´ÌåÏÖ´óÓÚ¼´ÊÇ£¬genderʹÓÃÁ˼´ÊÇÅÌÎʱí´ïʽ£¬ÕâÑù£¬ÎÒÃǾͿÉÒÔÍê³É¶àÌõ¼þÅÌÎÊ¡£
×ܽáÆðÀ´£¬thinkphp¿ò¼ÜÏÂɨ³ýÌض¨Ãü¾ÝµÄÒªÁì¾ÍÊÇÔÚÊý¾ÝÅÌÎÊʱ¼ÓÈë¹ýÂËÌõ¼þ¡£ÐèҪעÖصÄÊÇ£¬ÎÒÃÇÐèÒªÎÞа¶à±äµØʹÓÃÅÌÎʱí´ïʽÀ´Öª×ã¶àÌõ¼þÅÌÎʵÄÐèÇó¡£
ÒÔÉϾÍÊÇthinkphpÔõôɨ³ýÌض¨Ãü¾ÝÏÔʾµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡