zoukankan      html  css  js  c++  java
  • thinkphp5项目--企业单车网站(九)(加强复习啊)(花了那么多时间写的博客,不复习太浪费了)

    thinkphp5项目--企业单车网站(九)(加强复习啊)(花了那么多时间写的博客,不复习太浪费了)

    项目地址

    fry404006308/BicycleEnterpriseWebsite: Bicycle Enterprise Website
    https://github.com/fry404006308/BicycleEnterpriseWebsite

    一、总结

    二、js警告框warning事件

    <a href="#" onClick="warning('确实要删除吗', '{:url('article/delete',array('id'=>$vo['aid']))}')" class="btn btn-danger btn-sm shiny">

    1、这里onclick调用

    2、warning的使用:warning('参数1','url')

    三、文章删除逻辑

    删除数据库字段,同时也要删除资源,比如图片

    这里用了钩子函数,模型事件,before_delete

    控制器代码:

    1 public function delete(){
    2     $id = input('id');
    3     if(ModelArticle::destroy($id)){ //1、模型的静态方法destroy删除
    4         $this->success('删除文章成功!','article/lst');
    5     }else{
    6         $this->error('删除文章失败!');
    7     }
    8 }

    模型代码:

     1 <?php
     2 namespace appadminmodel;
     3 use thinkModel;
     4 
     5 class Article extends Model
     6 {
     7     protected static function init() //2、注册模型事件
     8     {
     9         Article::event('before_delete', function ($datain) { //3、删除图片操作
    10             //1、删除原来的图片
    11             $dataArticle = Article::find($datain->aid);
    12             /*$_SERVER['DOCUMENT_ROOT'] string(129) "E:/2017-02-21--SoftWare/PHP/SOFTWARE/phpStudy_New/PHPTutorial/WWW/github/BicycleEnterpriseWebsite/BicycleEnterpriseWebsite/public"*/
    13             $thumbpath=$_SERVER['DOCUMENT_ROOT'].$dataArticle->athumb;
    14             if(file_exists($thumbpath)){
    15                 @unlink($thumbpath);
    16             }
    17         });
    18     }
    19 }    
  • 相关阅读:
    java链接linux服务器,命令操作
    linux中php项目无法发送邮件:PEAR mail package is not installed
    linux下部署php项目-Apache、php、mysql关联
    MyEclipse黑色主题
    MyEclipse优化-六步攻略
    致产品
    万物归宗
    【产品渗透:移动端平台与纯应用APP产品的相互嵌入】
    【异类--一万小时定律】
    【活法】
  • 原文地址:https://www.cnblogs.com/Renyi-Fan/p/9038984.html
Copyright © 2011-2022 走看看