尊龙凯时人生就是搏

thinkphp5.0ÔõôÔöɾ²é¸Ä

Ò»¡¢Ð¡Ðò

ThinkPHPÊÇÒ»¿î¿ªÔ´µÄPHP¿ª·¢¿ò¼Ü£¬ÖÂÁ¦ÓÚΪ¿ª·¢Õß¹¹½¨¸ßЧ¡¢Îȹ̡¢Çå¾²ÇÒÒ×ÓÚÀ©Õ¹µÄWEBÓ¦ÓÃÌṩ×ÊÖú¡£thinkPHP ¿ò¼Ü°æ±¾Éý¼¶ºÍÐÂÔö¹¦Ð§ÊDz»¿É×èÖ¹µÄ£¬ÏÂÃæÎÒ½«Í¨¹ýÏÈÈÝÔõÑùʹÓÃTP5.0ʵÏÖÔöɾ²é¸Ä¹¦Ð§£¬Ï£ÍûÄܹ»¶Ô¸÷ÈËÓÐËù×ÊÖú¡£

¶þ¡¢ÊµÏÖÔöɾ²é¸ÄµÄ°ì·¨

×¼±¸Ê¾ÀýÊý¾Ý¿âºÍ±í

Ê×ÏÈ£¬ÐèҪ׼±¸Ò»¸öʾÀýÊý¾Ý¿âºÍ±í£¬ÒÔÏÂÊÇÒ»¸öʾÀý±í£º

CREATE TABLE think_user (

 id int(11) NOT NULL AUTO_INCREMENT COMMENT ‘Óû§id’,

 name varchar(255) DEFAULT NULL COMMENT ‘Óû§êdzƒ,

 email varchar(255) DEFAULT NULL COMMENT ‘Óû§ÓÊÏä’,

 status tinyint(4) DEFAULT ‘1’ COMMENT ‘Óû§×´Ì¬’,

 create_time datetime DEFAULT NULL COMMENT ‘½¨Éèʱ¼ä’,

 update_time datetime DEFAULT NULL COMMENT ‘¸üÐÂʱ¼ä’,

 PRIMARY KEY (id)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT=’Óû§ÐÅÏ¢±í’;

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

½¨ÉèÓû§Ä£×ӺͿØÖÆÆ÷

Ê×ÏÈÐèҪͨ¹ýÌìÉúÏÂÁîÀ´½¨ÉèÓû§Ä£×ӺͿØÖÆÆ÷£º

php think make:model User

php think make:controller User

¿É²Î¿¼ÏÂÁîÎĵµ£ºhttps://www.kancloud.cn/manual/thinkphp5_1/353947

ʵÏÖÓû§Áбí

ÔÚÓû§¿ØÖÆÆ÷ÖУ¬ÎÒÃÇÐèҪʵÏÖÓû§ÁбíµÄչʾ£¬ÊµÏÖ´úÂëÈçÏ£º

public function index()

{

 $users = UserModel::all();
 $this->assign('users', $users);
 return $this->fetch();

µÇ¼ºó¸´ÖÆ

}

ÆäÖУ¬UserModelΪÔÚµÚ2²½Öн¨ÉèµÄÓÃÓÚ²Ù×÷Óû§±íµÄÄ£×Ó£¬$usersÌåÏÖ´Óuser±íÖлñÈ¡µÄËùÓÐÓû§ÐÅÏ¢£¬$this->assign()ÓÃÓÚÏòÄ£°åÖÐת´ï±äÁ¿£¬×îºóͨ¹ý$this->fetch()ÒªÁìäÖȾģ°å¡£

ʵÏÖÓû§Ìí¼Ó

Óû§Ìí¼ÓµÄʵÏÖÏà¶Ô½Ï¼òÆÓ£¬ÈçÏÂÒ»¸öʵÏֵIJο¼´úÂ룺

public function add()

{

 if (Request::instance()->isPost()) {
     $user = new UserModel;
     $user->name = input('name');
     $user->email = input('email');
     if ($user->save()) {
         return $this->success('Óû§Ìí¼ÓÀֳɣ¡', url('index'));
     } else {
         return $this->error('Óû§Ìí¼Óʧ°Ü£¡');
     }
 }
 return $this->fetch();

µÇ¼ºó¸´ÖÆ

}

ʵÏÖÓû§±à¼­

Óû§±à¼­µÄʵÏÖÐèÒª¸ü¶àµÄ×¢ÖØ£¬ÏêϸʵÏÖ´úÂëÈçÏ£º

public function edit($id)

{

 $user = UserModel::get($id);
 if (Request::instance()->isPost()) {
     $user->name = input('name');
     $user->email = input('email');
     if ($user->save()) {
         return $this->success('Óû§¸üÐÂÀֳɣ¡', url('index'));
     } else {
         return $this->error('Óû§¸üÐÂʧ°Ü£¡');
     }
 }
 $this->assign('user', $user);
 return $this->fetch();

µÇ¼ºó¸´ÖÆ

}

ÆäÖУ¬$id´ú±í±à¼­µÄÓû§Id£¬UserModel::get($id)ÓÃÓÚ»ñÈ¡¶ÔÓ¦µÄÓû§ÐÅÏ¢£¬$this->assign()ÓÃÓÚ´«Öµ¡£

ʵÏÖÓû§É¾³ý

Óû§É¾³ýÐèÒªÉóÉ÷²Ù×÷£¬ÒÔÏÂÊÇÒ»¸ö»ù±¾µÄɾ³ýʵÏÖ£º

public function delete($id)

{

 $user = UserModel::get($id);
 if ($user) {
     $user->delete();
     return $this->success('Óû§É¾³ýÀֳɣ¡', url('index'));
 } else {
     return $this->error('Óû§²»±£´æ£¡');
 }

µÇ¼ºó¸´ÖÆ

}

´úÂë²âÊÔ

ÒÔÉÏ´úÂëÒѾ­ÊµÏÖÁËÓû§ÖÎÀíµÄ»ù±¾¹¦Ð§£¬¿ÉÒÔͨ¹ý»á¼ûÒÔÏÂURL²âÊÔ´úÂ룺

»á¼û /user/index ¿ÉÒÔÉó²éµ½Óû§Áбí

»á¼û /user/add ¿ÉÒÔÌí¼ÓеÄÓû§

»á¼û /user/edit/id ±à¼­Ö¸¶¨IDµÄÓû§

»á¼û /user/delete/id ɾ³ýÖ¸¶¨IDµÄÓû§

Èý¡¢×ܽá

ÔÚTP5.0ÖÐʵÏÖÔöɾ²é¸ÄµÄ¹¦Ð§£¬¿ÉÒÔ¼ÓËÙ¿ª·¢Ö°Ô±µÄ¿ª·¢Ð§ÂÊ¡£Í¨¹ýÒÔÉϵÄʵÏÖ°ì·¨£¬¿ÉÒÔ×ÊÖú¿ª·¢Ö°Ô±ÊµÏÖ¼òÆÓµÄÔöɾ²é¸Ä¹¦Ð§£¬Í¬Ê±Ò²¿ÉÒԲο¼TP5.0¹Ù·½ÎĵµÀ´¸üÉîÈëµØÏàʶTP5.0¿ò¼Ü¡£

ÒÔÉϾÍÊÇthinkphp5.0ÔõôÔöɾ²é¸ÄµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是搏ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是搏ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是搏

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ