分类目录归档:None

thinkCMF 登入后台的页面设置

位置:/你的项目目录/vendor/thinkcmf/cmf-app/src/admin/controller/MainController.php

其中的:public function index(){

}

中添加跳转。

举例:


    public function index()
    {
        $aid=cmf_get_current_admin_id();
        if($aid>1&&$aid<30){
            return $this->redirect(url("portal/topics/search"));//跳转到会议页面,直接跳转,后期需要修改
        }

文件上传 Thinkcmf thinkphp

前端代码:

<div class="row">
                    <div class="file_model col-md-12">
                        <script type="text/html" id="files-item-tpl">
                                <li id="saved-file{id}">
                                    <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
                                    <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
                                            style="width: 200px;" title="文件名称">
                                    <a class="btn btn-info" id="file-{id}-preview" href="{preview_url}" target="_blank"><i class="fa fa-download fa-fw"></i></a>
                                    <a class="btn btn-default" href="javascript:uploadOne('文件上传','#file-{id}','file');"><i class="fa fa-upload fa-fw"></i></a>
                                    <a class="btn btn-danger" href="javascript:(function(){$('#saved-file{id}').remove();})();"><i class="fa fa-trash fa-fw"></i></a>
                                    <a class="btn btn-success" href="javascript:(function(){$('#saved-file{id}').before($('#saved-file{id}').next());})();"><i class="fa fa-arrow-down fa-fw"></i></a>
                                </li>
                            </script>

                        <div class="upload_file_div">
                            <h3>附件</h3>
                            <ul id="files" class="pic-list list-unstyled form-inline">
                            </ul>
                            <a href="javascript:uploadMultiFile('附件上传','#files','files-item-tpl','file');"
                                class="btn btn-default">选择文件</a>
                        </div>
                    </div>
                </div>
                <hr>

JS动态添加DIV 使用onclick绑定方法调用本地属性 删除onclick

以及其调用方法使用(event) ,$(event.currentTarget) 来调用方法

JS动态添加DIV 使用onclick绑定方法调用本地属性

<script>
     var div=$("<div class='one' onclick='onex(event)'>ssssssssss</div>");
     div.attr("id","div_aaaa");
     $("#info").append(div);


     function onex(event){
            alert($(event.currentTarget).attr("id"));
        }
</script>

button的onclick 实现删除本标签或者父辈标签

<button class="child" onclick="this.parentNode.parentNode.remove()">删除</button>

Thinkphp事务

根据ACID一致性原则,事务对于要修改连续相关的多条数据,非常便于操作。如果执行过程中,任意一步不成功就回滚,保存原有数据。

在模型中需要引入:

use think\facade\Db;

在开始事务前创建事务,Db::startTrans() 执行使用 try 执行语句,成功则 Db::commit() ,若出现问题在catch结构 中执行Db::roollback()

Db::startTrans();

try(

//执行相关语句

Db::commit();

)catch(\Exception $e){

Db::rollback();

return null;

}

相关代码范例:(其中一个方法)

Db::startTrans();
try {
    // 创建用户模型实例
    $userModel = new UserModel();
    // 创建订单模型实例
    $orderModel = new OrderModel();

    // 插入用户数据
    $userModel->save(['name' => 'bbb', 'age' => 20]);
    // 插入订单数据
    $orderModel->save(['user_id' => $userModel->id, 'amount' => 100]);

    // 提交事务
    Db::commit();
} catch (\Exception $e) {
    // 回滚事务
    Db::rollback();
}

手动触发事务

使用throw new \Exception(‘插入第二条数据失败’); 触发事务,捕获错误的信息$e->getMessage()

Db::startTrans();
    try {
        // 插入第一条数据
        $result1 = Db::table('table1')->insertGetId($data1);
        if (!$result1) {
            throw new \Exception('插入第一条数据失败');
        }

        // 插入第二条数据
        $result2 = Db::table('table2')->insert($data2);
        if (!$result2) {
            throw new \Exception('插入第二条数据失败');
        }

        // 提交事务
        Db::commit();
        return ['status' => 'success', 'message' => '数据插入成功'];
    } catch (\Exception $e) {
        // 回滚事务
        Db::rollback();
        // 返回错误信息
        return ['status' => 'error', 'message' => $e->getMessage()];
    }
}