×ðÁú¿­Ê±¹ÙÍøµÇ¼

thinkphpÔõôɾ³ý·ÖÀà

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏàʶ·ÖÀàÔÚÍøÕ¾ÖеÄ×÷Óá£ÔÚÐí¶àÍøÕ¾ÖУ¬·ÖÀàÊǺÜÊÇÖ÷ÒªµÄÒ»¸ö¿´·¨¡£ÔÚµç×ÓÉÌÎñÍøÕ¾ÉÏ£¬ÉÌÆ·ÐèҪƾ֤²î±ðµÄÖÖ±ð¾ÙÐл®·Ö£¨Èç´ò°ç¡¢¼Ò¾Ó¡¢ÊýÂëµÈ£©£¬ÒÔÀû±ãÓû§²éÕҺ͹ºÖá£ÎªÁËÀû±ãÓû§ÔĶÁ£¬ÎÒÃÇÐèÒª½«ÐÂÎÅÍøÕ¾µÄÄÚÈÝƾ֤²î±ð·ÖÀࣨÈ纣ÄÚ¡¢¹ú¼Ê¡¢ÓéÀÖ¡¢ÌåÓýµÈ£©¾ÙÐйéÀà¡£Òò´Ë£¬·ÖÀàµÄÖ÷ÒªÐÔ²»ÑÔ¶øÓ÷¡£

È»¶ø£¬µ±·ÖÀ౬·¢×ª±äʱ£¬ÎÒÃǾÍÐèÒª¶ÔÆä¾ÙÐвÙ×÷¡£Ê¹ÓÃThinkPHP¿ª·¢µÄÍøÕ¾ÖУ¬ÎÒÃÇ¿ÉʹÓøÿò¼ÜÌṩµÄModelÀàÖ´ÐÐɾ³ý²Ù×÷¡£ÏÂÃ棬ÎÒÃǽ«ÒÔÒ»¸ö¼òÆÓµÄʾÀýÀ´ËµÃ÷ÔõÑùɾ³ý·ÖÀà¡£

¼ÙÉèÎÒÃÇÓÐÒ»¸öÃûΪCategoryµÄÄ£×ÓÀ࣬ÓÃÓÚÌåÏÖ·ÖÀà¡£The model class is defined in the application\common\model directory.¡£Õâ¸ö·ÖÀàÄ£×ÓÓÐÁ½¸öÊôÐÔ£ºidºÍname£¬»®·Ö¶ÔÓ¦·ÖÀàµÄ±àºÅºÍÃû³Æ¡£

ΪÁËʵÏÖɾ³ý·ÖÀàµÄ¹¦Ð§£¬ÎÒÃÇÐèÒªÔÚ¿ØÖÆÆ÷Öбàд¶ÔÓ¦µÄ´úÂë¡£¼ÙÉèÎÒÃÇʹÓÃÁËÃûΪCategoryControllerµÄ¿ØÖÆÆ÷À࣬¿ÉÒÔÔÚ¸ÃÀàÖнç˵һ¸ödeleteÒªÁìÀ´É¾³ý·ÖÀà¡£ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý´úÂ룺

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

<?php
namespace app\index\controller;

use think\Controller;
use app\common\model\Category;

class CategoryController extends Controller
{
    public function delete($id)
    {
        // ƾ֤·ÖÀà±àºÅ»ñÈ¡·ÖÀ๤¾ß
        $category = Category::get($id);
        
        // ÅжϷÖÀàÊÇ·ñ±£´æ
        if (!$category)
        {
            $this->error('·ÖÀ಻±£´æ');
        }
        
        // ɾ³ý·ÖÀà
        $result = $category->delete();
        
        // ÅжÑþ³ØýЧ¹û²¢×÷³öÏìÓ¦µÄ²Ù×÷
        if ($result)
        {
            $this->success('ɾ³ýÀÖ³É');
        }
        else
        {
            $this->error('ɾ³ýʧ°Ü');
        }
    }
}

µÇ¼ºó¸´ÖÆ

ÔÚÒÔÉÏ´úÂëƬ¶ÏÖУ¬ÎÒÃÇÊ×ÏÈͨ¹ý´ÓÊý¾Ý¿âÖлñÈ¡¶ÔÓ¦µÄ·ÖÀà±àºÅ$id£¬»ñµÃÏìÓ¦µÄ·ÖÀ๤¾ß$category¡£½Ó×Å£¬ÎÒÃÇÅжϸ÷ÖÀàÊÇ·ñ±£´æ£¬ÈôÊDz»±£´æ£¬Ôò·µ»Ø¹ýʧÐÅÏ¢¡£

Èô·ÖÀà±£´æ£¬ÔòŲÓ÷ÖÀ๤¾ßµÄdeleteÒªÁìÀ´É¾³ý¸Ã·ÖÀà¡£Ö´Ðд˲Ù×÷½«´ÓÊý¾Ý¿âÖÐɾ³ý·ÖÀ࣬ͬʱ·µ»Øɾ³ýµÄЧ¹û $result¡£×îÖÕ£¬ÎÒÃÇ»áƾ֤ɾ³ýµÄЧ¹û½ÓÄÉÏìÓ¦µÄ²½·¥£ºÈôɾ³ýÀֳɣ¬Ôò·´ÏìÀÖ³ÉÐÅÏ¢ £»²»È»·´Ïìʧ°ÜÐÅÏ¢¡£

ÐèҪעÖصÄÊÇ£¬ÈôÊÇ·ÖÀàÓëÆäËûÊý¾Ý±£´æ¹ØÁª¹Øϵ£¬ÀýÈçÓëij¸öÉÌÆ·»òÐÂÎÅÏà¹ØÁª£¬ÄÇôɾ³ý·ÖÀàʱÐèҪ˼Á¿ÕâЩ¹ØÁª¹Øϵ¡£ÔÚÉÏÊöʾÀýÖУ¬ÎÒÃDz¢Ã»ÓÐ˼Á¿·ÖÀàÓëÆäËûÊý¾ÝµÄ¹ØÁª¹Øϵ¡£

ÒÔÉϾÍÊÇthinkphpÔõôɾ³ý·ÖÀàµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ