美文网首页
thinkCMF 字典表相关

thinkCMF 字典表相关

作者: CoderZb | 来源:发表于2018-12-13 09:39 被阅读31次
字典表添加的结构如下
image.png

展示产品服务字典表,可以发现表名不对

image.png

解决办法:改成这样就正确了,所以对应的后台的表名为cmf_portal_service,除非表名改了,否则后台访问表的时候必须是这种格式。

image.png image.png

可以看到如果parent_id的值等于id的值,那么该parent_id对应的内容就从属于该id,下图中的A从属于B,即:债券融资服务从属于科技金融服务

image.png

相关文件

BankMangerController.php文件

<?php

use app\hatching\model\PortalServiceModel;
class BankMangerController extends AdminBaseController
{
    /**
    * 让该控制器与serviceproductadd.html关联
    */
    public function serviceproductadd()
    {
        $parentId            = $this->request->param('parent', 0, 'intval');
        $PortalServiceModel = new PortalServiceModel();
        $categoriesTree      = $PortalServiceModel->adminCategoryTree($parentId);
        //print_r($categoriesTree);
        $this->assign('categories_tree', $categoriesTree);
        return $this->fetch();
    }

}

PortalServiceModel.php文件

<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------
namespace app\hatching\model;

use think\Db;
use think\Model;

class PortalServiceModel extends Model
{
    // $selectId为传递过来的id,仅用于默认选择树形结构中的某个分支
    public function adminCategoryTree($selectId)
    {
        // 从$this指向的表中取数据存储到$中。
        $categories = $this->order("id ASC")->where('parent_id',0)->select()->toArray();
        $str="";
        // 外层foreach执行一次,内容foreach执行一个循环。
        foreach ($categories as $item) {
            // 遍历所有的大类,即遍历categories中的内容,遍历出来的每个item都是大类。如果树形中的某个id等于传过来的id,就把selected赋值给左边的变量$selected存储起来,否则$selected为空
            $selected = $selectId == $item['id'] ? "selected" : "";
            $str .= "<option value=".$item['id']." ". $selected. ">".$item['name']."</option>";
            // "<option value=93>金融服务</option>"

            // 拿到$categories中遍历出来的某个大类(某个item)存储到categories_er中,然后利用foreach取出某个大类下的所有小类
            $categories_er=$this->where('parent_id',$item['id'])->select()->toArray();
            foreach ($categories_er as $key) {
                // 遍历某个大类下,即遍历categories_er中的内容,,遍历出来的每个key都是某个大类下对应的小类。如果树形中的某个id等于传递过来的id,就把selected赋值给左边的变量$selected存储起来,否则$selected为空
                $selected = $selectId == $key['id'] ? "selected" : "";
                // 小类前边显示└─,包在<option></option>里面返回给调用者,调用者然后将内容显示到html中
                $str .= "<option value=".$key['id']." ". $selected. ">&nbsp;&nbsp;└─".$key['name']."</option>";
            }

        }
        return $str;
    }

}

相关文章

  • thinkCMF 字典表相关

    字典表添加的结构如下 展示产品服务字典表,可以发现表名不对 解决办法:改成这样就正确了,所以对应的后台的表名为cm...

  • ThinkCMF相关

    1、后台登录验证码难度设置 /vendor/topthink/think-captcha/src/Captcha....

  • thinkCMF 表关联

    通过a.type_id=b.id``使service表和portal_service表关联。关联目的:用于取出po...

  • urllib.parse

    转换相关 .quote() 编码已构造查询字符串 .urlencode() 编码字典表 需要POST访问时需要...

  • 程序日记2018-04-27

    thinkcmf更改步骤: 2、后台添加类似文章结构的学生模块:(1)首先在mysql插入表结构包括 portal...

  • redis笔记:字典

    本人博客同步发表,排版更佳 字典实现 哈希表 哈希表节点 字典 字典类型特定函数 redis会为用途不同的字典设置...

  • 字典表

    参考博客:https://www.cnblogs.com/jpfss/p/10418873.html[https:...

  • 4.字典

    字典 1. 字典的实现 Redis的字典使用哈希表作为底层实现,一个哈希表里面可以有多个哈希表节点,每个哈希表节点...

  • python学习笔记 练习

    练习 :把字典文本dictionary.txt 的内容写入数据表中,再通过模糊查询找到相关的单词。dictiona...

  • mysql语句

    表结构 表数据 数据字典SQL

网友评论

      本文标题:thinkCMF 字典表相关

      本文链接:https://www.haomeiwen.com/subject/qbqvhqtx.html