ÔõôʹÓÃThinkPHPʵÏÖÎÄÕÂÌí¼Ó½çÃæ
Ò»¡¢½¨ÉèÊý¾Ý¿â
Ê×ÏÈ£¬ÎÒÃÇÐèҪΪÎÒÃǵÄÎÄÕÂÌí¼ÓÒ³Ã潨ÉèÒ»¸öÊý¾Ý¿â¡£·¿ªphpMyAdmin»òÆäËûÊý¾Ý¿âÖÎÀí¹¤¾ß£¬½¨ÉèÒ»¸öÃûΪ¡°blog¡±µÄÊý¾Ý¿â£¬²¢ÔÚÆäÖн¨ÉèÒ»¸öÃûΪ¡°article¡±µÄÊý¾Ý±í¡£Êý¾Ý±íµÄ×ֶΰüÀ¨£ºid(ÎÄÕµÄID)£¬title(ÎÄÕµÄÎÊÌâ)£¬content(ÎÄÕµÄÄÚÈÝ)£¬create_time(ÎÄÕµĽ¨Éèʱ¼ä)£¬update_time(ÎÄÕµĸüÐÂʱ¼ä)¡£
¶þ¡¢½¨ÉèÄ£×Ó£¬¿ØÖÆÆ÷ºÍÊÓͼ
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÄ£×Ó¡¢¿ØÖÆÆ÷ºÍÊÓͼ£¬ÒÔ¼°ÏìÓ¦µÄ²Ù×÷ÒªÁì¡£ÎÒÃÇÐèÒªÏȽ¨ÉèÒ»¸öArticleÄ£×Ó£¬ÕâÑù¾Í¿ÉÒÔËæʱ»ñÈ¡ÎÄÕÂÊý¾Ý¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÔÚThinkPHPÖУ¬½¨ÉèÄ£×ÓºÜÊǼòÆÓ£¬Ö»ÐèÔÚapplicationĿ¼ÏµÄcommonĿ¼Ï½¨ÉèÒ»¸öArticle.phpÎļþ£¬²¢½«ÒÔÏ´úÂëÌí¼Óµ½ÆäÖУº
<?php namespace app\common\model; use think\Model; class Article extends Model { //±íÃû protected $table = 'article'; }
µÇ¼ºó¸´ÖÆ
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸ö¿ØÖÆÆ÷£¬¸Ã¿ØÖÆÆ÷ÓÃÓÚ´¦ÀíÎÄÕµÄÌí¼Ó²Ù×÷ÒÔ¼°äÖȾÎÄÕÂÌí¼ÓÒ³Ãæ¡£
ÔÚThinkPHPÖУ¬½¨Éè¿ØÖÆÆ÷Ò²ºÜÊǼòÆÓ£¬Ö»ÐèÔÚapplicationĿ¼ÏµÄadminĿ¼Ï½¨ÉèÒ»¸öArticle.phpÎļþ£¬²¢½«ÒÔÏ´úÂëÌí¼Óµ½ÆäÖУº
<?php namespace app\admin\controller; use think\Controller; use app\common\model\Article; class Article extends Controller { public function add() { if(request()->isPost()){ $data = input('post.'); $data['create_time'] = time(); $data['update_time'] = time(); $article = new Article(); if($article->allowField(true)->save($data)){ $this->success('Ìí¼ÓÀֳɣ¡'); } $this->error('Ìí¼Óʧ°Ü£¡'); } return view(); } }
µÇ¼ºó¸´ÖÆ
¸Ã¿ØÖÆÆ÷µÄaddÒªÁì±»ÓÃÓÚ·ºÆðÎÄÕÂÌí¼ÓÒ³Ãæ²¢´¦ÀíÌí¼ÓÎÄÕµIJÙ×÷¡£ÔÚÉúÑÄÎÄÕÂʱ£¬ÐèÒª½«ÎÊÌâ¡¢ÄÚÈÝ¡¢½¨Éèʱ¼äºÍ¸üÐÂʱ¼ä´æ´¢ÔÚÊý¾Ý¿â±íÖС£
×îºó£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÊÓͼ£¬¸ÃÊÓͼÓÃÓÚÏÔʾÎÄÕÂÌí¼Ó½çÃæ¡£ÔÚapplicationĿ¼ÏµÄadminĿ¼Ï½¨ÉèÒ»¸öarticle/add.htmlÎļþ£¬²¢½«ÒÔÏ´úÂëÌí¼Óµ½ÆäÖУº
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Ìí¼ÓÎÄÕÂ</title> </head> <body> <form action="" method="post"> <div> <label for="title">ÎÊÌ⣺</label> <input type="text" name="title" id="title"> </div> <div> <label for="content">ÄÚÈÝ£º</label> <textarea name="content" id="content" cols="30" rows="10"></textarea> </div> <div> <input type="submit" value="Ìí¼Ó"> <input type="reset" value="ÖØÖÃ"> </div> </form> </body> </html>
µÇ¼ºó¸´ÖÆ
Èý¡¢²âÊÔÎÄÕÂÌí¼Ó½çÃæ
Íê³ÉÒÔÉÏ°ì·¨ºó£¬ÎÒÃÇÒѾ¿ÉÒÔ²âÊÔÎÒÃǵÄÎÄÕÂÌí¼Ó½çÃæÁË¡£ÔÚä¯ÀÀÆ÷ÖÐÊäÈë¡°http://your_domain/admin/article/add¡±£¬¼´¿É»á¼ûÎÄÕÂÌí¼ÓÒ³Ãæ¡£Òª½«ÎÄÕÂÉúÑĵ½Êý¾Ý¿âÖУ¬Ö»ÐèÔÚÒ³ÃæÖÐÌîдÎÄÕÂÎÊÌâºÍÄÚÈÝ£¬È»ºóµã»÷¡°Ìí¼Ó¡±°´Å¥¡£
ÒÔÉϾÍÊÇÔõôʹÓÃThinkPHPʵÏÖÎÄÕÂÌí¼Ó½çÃæµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡