知识笔记(五十七)———fastadmin编辑方法

通过一些方法来进行编辑

首先,在控制器中要引入 think\Db;的方法

复制代码
use think\Db;

然后通过引入的 Db来进行编辑方法的实现

复制代码
    /**
     * 编辑
     */
    public function edit($ids = null)
    {
        //Id为表中的Id
		$row = $this->model->get( [ 'Id' => $ids ] );
		// 如果id不存在
		if ( !$row ) {
			$this->error( __( 'No Results were found' ) );
		}
		//如果点击确认编辑执行
		if ( $this->request->isPost() ) {
			// 获取编辑所有字段和数据
			$params = $this->request->post( 'row/a' );
			//如果获取到parmas则执行
			if ( $params ) {
				Db::startTrans();
				//事务
				//成功
				try {
					//编辑
					$result = $row->save( $params );
					// 如果编辑失败则会提示
					if ( $result === false )exception( $row->getError() );
					Db::commit();
					//提交
				} catch ( \Exception $e ) {
					//失败
					Db::rollback();
					//回滚
					$this->error( $e->getMessage() );
				}
				$this->success();
				//编辑成功
			}
		}
		// 点击编辑是回显数据
		$this->view->assign( 'row', $row );
		return $this->view->fetch();

        // if ($this->request->isPost()) {
        //     $this->token();
        // }
        // $row = $this->model->get($ids);
        // $this->modelValidate = true;
        // if (!$row) {
        //     $this->error(__('No Results were found'));
        // }
        // $this->view->assign('row',$row);
        // return $this->view->fetch();
    }
相关推荐
10岁的博客14 小时前
Chrome 扩展安全攻防实录:从权限模型到真实漏洞复盘
前端·chrome·安全
凉、介14 小时前
深入理解 ARMv7-A | Generic Timer
笔记·学习·嵌入式·arm
Félix25114 小时前
Nacos学习笔记(SpringBoot/SpringCloud)
java·spring boot·spring
文丑颜不良啊14 小时前
LeetCode1581~1600题目解析
java·leetcode
香蕉大香蕉(06敬畏市场)14 小时前
MySQL 单点详解(06)
java·数据库·mysql·博客·实习
QianhangQianping14 小时前
WebSocket实时推送+ HTTP 定时轮询:一块大屏两套取数怎么不打架
前端·websocket·网络协议·http·低代码·架构·数据可视化
Eider199814 小时前
Python基础知识之并发相关-2
开发语言·前端·python
用户693717500138414 小时前
AI 能写代码,但工程架构还是应该由人来定
前端·后端
lqbzlll14 小时前
Spring Boot 开启虚拟线程后接口反而变慢了?4 个排查方向和对应修法
java·spring boot·后端
n 55!w !10814 小时前
MySQL笔记整理2
数据库·笔记·mysql