×ðÁú¿­Ê±

ÔõÑùÔÚThinkPHP6ÖоÙÐв˵¥ÖÎÀí²Ù×÷£¿

thinkphp6ÊÇÒ»¿î¸ßЧ¡¢Çå¾²¡¢Îȹ̵Äphp¿ª·¢¿ò¼Ü£¬Ëü½ÓÄÉÁËÓÅÒìµÄmvc£¨model-view-controller£©Éè¼Æģʽ£¬Îª¿ª·¢Ö°Ô±ÌṩÁËÎÞаÇÒ¼òÆӵĿª·¢·½·¨¡£ÔÚËüµÄ×ÊÖúÏ£¬¿ª·¢Ö°Ô±¿ÉÒÔ¿ìËÙ¿ª·¢Ç¿Ê¢µÄwebÓ¦ÓóÌÐò¡£

¹ØÓÚ´ó´ó¶¼WebÓ¦ÓóÌÐò¶øÑÔ£¬²Ëµ¥ÖÎÀí¶¼ÊDZز»¿ÉÉٵĹ¦Ð§¡£±¾ÎĽ«ÏÈÈÝÔÚThinkPHP6ÖÐÔõÑù¾ÙÐв˵¥ÖÎÀí²Ù×÷¡£

½¨Éè²Ëµ¥Ä£×ÓÎļþ

Ê×ÏÈ£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸ö²Ëµ¥Ä£×ÓÎļþ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÔÚÖÕ¶ËÖн¨ÉèÒ»¸ö²Ëµ¥Ä£×ÓÎļþ£º

php think make:model admin/Menu

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁÔÚappĿ¼ÏµÄadmin×ÓĿ¼Öн¨ÉèÒ»¸öMenu.phpÎļþ£¬Ëü½«±»ÓÃ×÷²Ëµ¥Ä£×ÓÎļþ¡£

½¨Éè²Ëµ¥¿ØÖÆÆ÷Îļþ

ÔÚ¼ÌÐø½¨Éè²Ëµ¥¿ØÖÆÆ÷Îļþ֮ǰ£¬ÎÒÃÇÐèÒªÏȽ¨ÉèÒ»¸ö²Ëµ¥±íµÄÊý¾Ý¿âǨáãÎļþ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´ÌìÉúÒ»¸öÃûΪcreate_menu_tableµÄǨáãÎļþ£º

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

php think make:migration create_menu_table

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁÔÚdatabaseĿ¼ÏµÄmigrations×ÓĿ¼Öн¨ÉèÒ»¸öǨáãÎļþ¡£

½ÓÏÂÀ´£¬ÎÒÃÇÐèҪʹÓÃÒÔÏÂÏÂÁîÀ´Ö´ÐÐǨáãÎļþ²¢½¨Éè²Ëµ¥±í£º

php think migrate

µÇ¼ºó¸´ÖÆ

ÏÖÔÚ£¬ÎÒÃÇ¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÔÚÖÕ¶ËÖн¨ÉèÒ»¸ö²Ëµ¥¿ØÖÆÆ÷Îļþ£º

php think make:controller admin/Menu

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁÔÚappĿ¼ÏµÄadmin×ÓĿ¼Öн¨ÉèÒ»¸öÃûΪMenu.phpµÄ¿ØÖÆÆ÷Îļþ¡£

±àд²Ëµ¥ÖÎÀíÊÓͼÎļþ

ÎÒÃÇÐèÒª½¨ÉèһЩÊÓͼÎļþÀ´ÏÔʾ²Ëµ¥ÖÎÀíÒ³Ãæ¡£¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´½¨ÉèÒ»¸öÃûΪindex.htmlµÄÊÓͼÎļþ£º

php think make:view /help/admin/menu/index

µÇ¼ºó¸´ÖÆ

Õâ¸öÏÂÁÔÚappĿ¼ÏµÄadmin×ÓĿ¼Öн¨ÉèÒ»¸ö×ÓĿ¼menu£¬²¢ÔÚÆäÖн¨ÉèÒ»¸öÃûΪindex.htmlµÄÊÓͼÎļþ¡£

ÔÚindex.htmlÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃHTML¡¢CSSºÍJavaScript½¨ÉèÒ»¸öÑŹۡ¢Ò×ÓÚʹÓõIJ˵¥ÖÎÀí½çÃæ¡£

±àд²Ëµ¥ÖÎÀí²Ù×÷

ÏÖÔÚÎÒÃÇÒѾ­Íê³ÉÁ˲˵¥Ä£×Ó¡¢¿ØÖÆÆ÷ºÍÊÓͼÎļþµÄ½¨É裬½ÓÏÂÀ´ÎÒÃǽ«±àд²Ù×÷À´¾ÙÐв˵¥ÖÎÀí¡£

4.1 Ë÷Òý²Ù×÷

ÔÚapp/admin/controller/Menu.phpÎļþÖУ¬ÎÒÃÇ¿ÉÒÔ±àдһ¸öË÷Òý²Ù×÷£¬Ëü½«¶ÁÈ¡Êý¾Ý¿âÖеIJ˵¥Êý¾Ý£¬²¢½«ËüÃÇת´ï¸øÊÓͼÎļþ¾ÙÐÐÏÔʾ¡£

public function index()
{
    $menus = MenuModel::select();
    $this->assign('menus', $menus);
    return $this->fetch('index');
}

µÇ¼ºó¸´ÖÆ

ÔÚindex.htmlÊÓͼÎļþÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃforeachÑ­»·±éÀú²Ëµ¥Êý¾Ý²¢½«ËüÃÇÏÔʾÔÚÒ³ÃæÉÏ¡£

4.2 ½¨Éè²Ù×÷

ÎÒÃÇ¿ÉÒÔ±àдһ¸ö½¨Éè²Ù×÷£¬Ëü½«ÏòÊý¾Ý¿âÖÐÌí¼ÓÒ»¸öеIJ˵¥£¬²¢ÔÚÍê³Éºó½«Óû§Öض¨Ïòµ½²Ëµ¥ÖÎÀíÒ³Ãæ¡£

public function create()
{
    if (request()->isPost()) {
        $menu = new MenuModel;
        $menu->name = input('post.name');
        $menu->url = input('post.url');
        $menu->save();
        $this->success('²Ëµ¥½¨ÉèÀÖ³É', url('/help/admin/menu/index'));
    } else {
        return $this->fetch('create');
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚcreate.htmlÊÓͼÎļþÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃ±íµ¥Î»Ëؽ¨ÉèÒ»¸öеIJ˵¥¡£

4.3 ¸üвÙ×÷

ÎÒÃÇ¿ÉÒÔ±àдһ¸ö¸üвÙ×÷£¬Ëü½«¸üÐÂÖ¸¶¨²Ëµ¥µÄÐÅÏ¢£¬²¢ÔÚÍê³Éºó½«Óû§Öض¨Ïòµ½²Ëµ¥ÖÎÀíÒ³Ãæ¡£

public function update()
{
    $id = input('id');
    $menu = MenuModel::get($id);
    if (request()->isPost()) {
        $menu->name = input('post.name');
        $menu->url = input('post.url');
        $menu->save();
        $this->success('²Ëµ¥¸üÐÂÀÖ³É', url('/help/admin/menu/index'));
    } else {
        $this->assign('menu', $menu);
        return $this->fetch('update');
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚupdate.htmlÊÓͼÎļþÖУ¬ÎÒÃÇ¿ÉÒÔÏÔʾָ¶¨²Ëµ¥µÄÐÅÏ¢£¬²¢Ê¹ÓÃ±íµ¥Î»ËØÔÊÐíÓû§¸üв˵¥ÐÅÏ¢¡£

4.4 ɾ³ý²Ù×÷

ÎÒÃÇ¿ÉÒÔ±àдһ¸öɾ³ý²Ù×÷£¬Ëü½«´ÓÊý¾Ý¿âÖÐɾ³ýÖ¸¶¨µÄ²Ëµ¥£¬²¢ÔÚÍê³Éºó½«Óû§Öض¨Ïòµ½²Ëµ¥ÖÎÀíÒ³Ãæ¡£

public function delete()
{
    $id = input('id');
    $menu = MenuModel::get($id);
    $menu->delete();
    $this->success('²Ëµ¥É¾³ýÀÖ³É', url('/help/admin/menu/index'));
}

µÇ¼ºó¸´ÖÆ

ÔÚindex.htmlÊÓͼÎļþÖУ¬ÎÒÃÇ¿ÉÒÔʹÓÃÒ»¸öÁ´½ÓÔªÏòÀ´´¥·¢É¾³ý²Ù×÷¡£

ÒÔÉϾÍÊÇÔÚThinkPHP6ÖоÙÐв˵¥ÖÎÀí²Ù×÷µÄÏÈÈÝ¡£Í¨¹ýʹÓÃÕâЩ²Ù×÷£¬Äú¿ÉÒÔÇáËɵØÖÎÀíWebÓ¦ÓóÌÐòµÄ²Ëµ¥£¬²¢ÌṩÄúµÄÓû§Ò»¸öÓÅÒìµÄÓû§ÌåÑé¡£

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖоÙÐв˵¥ÖÎÀí²Ù×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

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

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

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