thinkphpÖеÄmÒªÁìÔõôʹÓÃ
thinkphpÖеÄmÒªÁìÊÇModelÒªÁìµÄËõд¡£Í¨³£ÓÃÓÚÊý¾Ý¿â²Ù×÷ºÍÊý¾Ý³¤ÆÚ»¯µÄʵÏÖÊÇModel£¬ËüÊÇÓ¦ÓóÌÐòÖеÄÒ»²¿·Ö¡£ModelÀàÔÚthinkphp¿ò¼ÜÖÐÌṩһ×é²Ù×÷Êý¾Ý¿âµÄº¯Êý£¬¿ÉÒÔÇáËÉʵÏÖÔöɾ¸Ä²éµÈ²Ù×÷¡£
ʹÓÃthinkphpµÄmÒªÁì¿ÉÒÔºÜÀû±ãµØ²Ù×÷ModelÀ࣬¾ÙÐÐÊý¾Ý¿âµÄ¶Áд¡£mÒªÁìµÄ»ù±¾Óï·¨ÊÇ£º
$model = M('table');
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬¡¯table¡¯ÊÇÊý¾Ý¿âÖеıíÃû£¬¿ÉÒÔÊÇÒ»¸ö×Ö·û´®»òÕß±äÁ¿¡£
MÒªÁìÓжà¸ö²ÎÊý£¬µÚÒ»¸ö²ÎÊýΪÊý¾Ý¿â±íÃû£¬ºóÃæµÄ²ÎÊýΪÊý¾Ý¿âÉèÖÃÐÅÏ¢£¬°üÀ¨Êý¾Ý¿âµÄµØµã¡¢Óû§Ãû¡¢ÃÜÂëµÈ¡£ÈôÊDz»ÉèÖúóÃæµÄ²ÎÊý£¬Ôò»á×Ô¶¯¼ÓÔØÏîÄ¿ÉèÖÃÎļþ¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ʹÓÃmÒªÁì²»µ«¿ÉÒÔ½¨ÉèModelÀàµÄʵÀý£¬»¹¿ÉÒÔ½¨ÉèÆäËû·ÇModelÀàµÄʵÀý¡£Í¨¹ýʹÓÃmÒªÁìʵÀý»¯À࣬Äú¿ÉÒÔ¶Ô¸ÃÀàÖ´ÐÐÏìÓ¦²Ù×÷£¬²¢ÇÒ¿ÉÒÔŲÓÃModelÀàËù½ç˵µÄÒªÁìºÍÊôÐÔ¡£
ÏÂÃæÊÇÒ»¸öʾÀý´úÂ룺
$user = M('user'); $user->where('id=1')->find();
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂ뽨ÉèÁËÒ»¸öÃûΪ$userµÄModelÀàʵÀý£¬²¢Ê¹ÓÃwhere()ÒªÁìºÍfind()ÒªÁìÅÌÎÊÁËÊý¾Ý¿â±íÖÐIDΪ1µÄ¼Í¼£¬È»ºó½«ÅÌÎÊЧ¹û´æ´¢ÔÚ$user±äÁ¿ÖС£
³ýÁËÅÌÎÊ£¬mÒªÁ컹¿ÉÒÔ¾ÙÐÐÊý¾ÝµÄÔöÌí¡¢Ð޸ĺÍɾ³ý¡£ÏÂÃæÊÇÒ»¸öÔöÌíÊý¾ÝµÄʾÀý´úÂ룺
$user = M('user'); $user->username = 'test'; $user->password = md5('123456'); $user->add();
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂ뽨ÉèÁËÒ»¸öÃûΪ$userµÄModelÀàʵÀý£¬²¢Ê¹ÓÃadd()ÒªÁìÏòÊý¾Ý¿â±íÖÐÔöÌíÁËÒ»Ìõ¼Í¼£¬ÆäÖаüÀ¨usernameºÍpasswordÁ½¸ö×ֶΣ¬ÃÜÂëͨ¹ýmd5º¯Êý¼ÓÃÜ¡£
³ýÁËÒÔÉÏʾÀýÖеij£ÓòÙ×÷£¬ModelÀ໹ÌṩÁ˶àÖÖÒªÁ죬Èçjoin()¡¢order()¡¢limit()µÈ£¬¿ÉÒÔ×ÊÖúÎÒÃǸüÎÞаµØ¾ÙÐÐÊý¾Ý¿â²Ù×÷¡£
ÒÔÉϾÍÊÇthinkphpÖеÄmÒªÁìÔõôʹÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡