知识笔记(五十七)———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();
    }
相关推荐
Hilaku几秒前
我踩爆了 CSS Module 的所有坑,别再被骗了
前端·css·react.js
筏.k几秒前
C++: 类 Class 的基础用法
android·java·c++
北城笑笑2 分钟前
Server 11 ,⭐通过脚本在全新 Ubuntu 系统中安装 Nginx 环境,安装到指定目录( 脚本安装Nginx )
linux·运维·前端·nginx·ubuntu
小赵学鸿蒙4 分钟前
如何使用第三方库中的@pura/harmony-utils(V1.3.3)申请授权工具类一
前端
断竿散人5 分钟前
CSS选择器与伪类:精准定位元素的终极指南!
前端
憨憨是条狗6 分钟前
在 Vue + Vant + ArcGIS 环境中设置 GraphicsLayer 的标题
前端
onebyte8bits6 分钟前
打造丝滑滚动体验:Scroll-driven Animations 正式上线!
前端·javascript·css·html·html5
elon_z7 分钟前
【项目实训#08】HarmonyOS知识图谱前端可视化实现
前端·echarts·知识图谱·harmonyos
得物技术8 分钟前
得物社区活动:组件化的演进与实践
java·大数据·前端
一条叫做nemo的鱼17 分钟前
从汇编的角度揭开C++ this指针的神秘面纱(下)
java·汇编·c++·函数调用·参数传递