当前位置: 首页 > news >正文

网站建站卡顿怎么办做网站用什么代码编写

网站建站卡顿怎么办,做网站用什么代码编写,做网站哪个编辑器好用,网站建设服务费属于buildAdmin的代码生成#xff0c;很像是 fastadmin 的生成模式#xff0c;当我们利用数据库生成了一个控制器的时候#xff0c;我们可以看到#xff0c; 它的生成代码很简洁 ?phpnamespace app\admin\controller\askanswer;use app\common\controller\Backend;/*** 回…buildAdmin的代码生成很像是 fastadmin 的生成模式当我们利用数据库生成了一个控制器的时候我们可以看到 它的生成代码很简洁 ?phpnamespace app\admin\controller\askanswer;use app\common\controller\Backend;/*** 回答管理*/ class Answer extends Backend //控制器继承了 backend {/*** Answer模型对象* var object* phpstan-var \app\admin\model\Answer*///定义了一个 模型对象也就是对应数据表的 模型protected object $model;//这里是在添加数据中 排除了一些自动生成的字段 在Backend中有对这些字段的调用protected array|string $preExcludeFields [id, create_time, update_time];//这里是设置了前端的快速搜索protected string|array $quickSearchField [id];public function initialize(): void{parent::initialize(); //这里用了父类的 初始化方法 做了一些 用户认证权限判断数据库连接检测等$this-model new \app\admin\model\Answer;$this-request-filter(clean_xss); //这里对 request 做了一次 xss 攻击的过滤}/*** 若需重写查看、编辑、删除等方法请复制 see \app\admin\library\traits\Backend 中对应的方法至此进行重写*/ }接着我们来到父类 backend 在追代码的过程中我没有看到 跨域的操作 因为fastadmin 在这里面是有跨域操作的一段代码的后来经过 整块代码搜索 才想起来 这是tp8了 是有中间键的而fastadmin中是tp5.0,没有中间键的 真正的 增删改查的代码 就在traits中 ?phpnamespace app\admin\library\traits;use Throwable; use think\facade\Config;/*** 后台控制器trait类* 已导入到 see \app\common\controller\Backend 中* 若需修改此类方法请复制方法至对应控制器后进行重写*/ trait Backend {/*** 排除入库字段* param array $params* return array*/protected function excludeFields(array $params): array{if (!is_array($this-preExcludeFields)) {$this-preExcludeFields explode(,, (string)$this-preExcludeFields);}foreach ($this-preExcludeFields as $field) {if (array_key_exists($field, $params)) {unset($params[$field]);}}return $params;}/*** 查看* throws Throwable*/public function index(): void{if ($this-request-param(select)) {$this-select();}list($where, $alias, $limit, $order) $this-queryBuilder();$res $this-model-field($this-indexField)-withJoin($this-withJoinTable, $this-withJoinType)-alias($alias)-where($where)-order($order)-paginate($limit);$this-success(, [list $res-items(),total $res-total(),remark get_route_remark(),]);}/*** 添加*/public function add(): void{if ($this-request-isPost()) {$data $this-request-post();if (!$data) {$this-error(__(Parameter %s can not be empty, []));}$data $this-excludeFields($data);if ($this-dataLimit $this-dataLimitFieldAutoFill) {$data[$this-dataLimitField] $this-auth-id;}$result false;$this-model-startTrans();try {// 模型验证if ($this-modelValidate) {$validate str_replace(\\model\\, \\validate\\, get_class($this-model));if (class_exists($validate)) {$validate new $validate;if ($this-modelSceneValidate) $validate-scene(add);$validate-check($data);}}$result $this-model-save($data);$this-model-commit();} catch (Throwable $e) {$this-model-rollback();$this-error($e-getMessage());}if ($result ! false) {$this-success(__(Added successfully));} else {$this-error(__(No rows were added));}}$this-error(__(Parameter error));}/*** 编辑* throws Throwable*/public function edit(): void{$id $this-request-param($this-model-getPk());$row $this-model-find($id);if (!$row) {$this-error(__(Record not found));}$dataLimitAdminIds $this-getDataLimitAdminIds();if ($dataLimitAdminIds !in_array($row[$this-dataLimitField], $dataLimitAdminIds)) {$this-error(__(You have no permission));}if ($this-request-isPost()) {$data $this-request-post();if (!$data) {$this-error(__(Parameter %s can not be empty, []));}$data $this-excludeFields($data);$result false;$this-model-startTrans();try {// 模型验证if ($this-modelValidate) {$validate str_replace(\\model\\, \\validate\\, get_class($this-model));if (class_exists($validate)) {$validate new $validate;if ($this-modelSceneValidate) $validate-scene(edit);$validate-check($data);}}$result $row-save($data);$this-model-commit();} catch (Throwable $e) {$this-model-rollback();$this-error($e-getMessage());}if ($result ! false) {$this-success(__(Update successful));} else {$this-error(__(No rows updated));}}$this-success(, [row $row]);}/*** 删除* param array $ids* throws Throwable*/public function del(array $ids []): void{if (!$this-request-isDelete() || !$ids) {$this-error(__(Parameter error));}$where [];$dataLimitAdminIds $this-getDataLimitAdminIds();if ($dataLimitAdminIds) {$where[] [$this-dataLimitField, in, $dataLimitAdminIds];}$pk $this-model-getPk();$where[] [$pk, in, $ids];$count 0;$data $this-model-where($where)-select();$this-model-startTrans();try {foreach ($data as $v) {$count $v-delete();}$this-model-commit();} catch (Throwable $e) {$this-model-rollback();$this-error($e-getMessage());}if ($count) {$this-success(__(Deleted successfully));} else {$this-error(__(No rows were deleted));}}/*** 排序* param int $id 排序主键值* param int $targetId 排序位置主键值* throws Throwable*/public function sortable(int $id, int $targetId): void{$dataLimitAdminIds $this-getDataLimitAdminIds();if ($dataLimitAdminIds) {$this-model-where($this-dataLimitField, in, $dataLimitAdminIds);}$row $this-model-find($id);$target $this-model-find($targetId);if (!$row || !$target) {$this-error(__(Record not found));}if ($row[$this-weighField] $target[$this-weighField]) {$autoSortEqWeight is_null($this-autoSortEqWeight) ? Config::get(buildadmin.auto_sort_eq_weight) : $this-autoSortEqWeight;if (!$autoSortEqWeight) {$this-error(__(Invalid collation because the weights of the two targets are equal));}// 自动重新整理排序$all $this-model-select();foreach ($all as $item) {$item[$this-weighField] $item[$this-model-getPk()];$item-save();}unset($all);// 重新获取$row $this-model-find($id);$target $this-model-find($targetId);}$backup $target[$this-weighField];$target[$this-weighField] $row[$this-weighField];$row[$this-weighField] $backup;$row-save();$target-save();$this-success();}/*** 加载为select(远程下拉选择框)数据默认还是走$this-index()方法* 必要时请在对应控制器类中重写*/public function select(): void{} }
http://www.w-s-a.com/news/781742/

相关文章:

  • 网站建设中 gif互联网新项目在哪里找
  • 做外包网站猎头公司英文
  • 房屋结构自建设计 网站海淀教育互动平台
  • 网络营销比赛 营销型网站策划热门搜索关键词
  • 网站建设图片代码网络设计师工资
  • 福建网站开发适合交换友情链接的是
  • 企业门户网站建站内乡微网站开发
  • 在线做logo印章网站一般到哪个网站找数据库
  • 哪些网站做免费送东西的广告6郑州人流医院哪家好
  • 高端做网站哪家好sem技术培训
  • 网站做等保是按照什么定级别的做网站的资源哪里找
  • 免费建站网页无需登陆潍坊高端模板建站
  • 北京php网站建设软通动力外包值得去吗
  • 优酷 做视频网站还能成功吗光谷做网站推广哪家好
  • 培训学校网站建设方案网站开发方案设计
  • 网站开发分支结构外贸网站做推广
  • 海南省城乡建设厅网站首页济南网站建设百家号
  • wordpress 图片命名吗北京seo优化哪家公司好
  • 国税网站页面申报撤销怎么做网站空间如何买
  • 简单的购物网站模板跨境建站平台
  • 网站主机多大html网站地图生成
  • 可信赖的邵阳网站建设德清做网站
  • 上传文件网站根目录wordpress博客管理
  • 网站seo优缺点网站建设公司咨
  • 网站设计需要会什么建设网站的目的以及意义
  • 怎么样推广自己的网站wordpress register_form
  • 网站公司建站凤翔网站建设
  • 网站建设协低价格的网站建设公司
  • 研发网站建设报价深圳网站建设前十名
  • 宠物发布网站模板wordpress中文免费电商模板