基于网站表单设计查询内容,以【证书查询】为例子

证书表字段:

证书名称:title
证书编号:zsbh
其他字段若干(开发者可自行创建)

实现需求:

1、在前端输入【证书名称+编号】查询出证书详情记录
2、在前端输入【证书编号】查询出详情记录


实现步骤:

1、创建证书表单,取名为zhengshu(随便命名)

{xunruicms_img_title}

2、在右侧进入自定义字段,创建一些字段

{xunruicms_img_title}

测试阶段,我只创建了两个字段,开发者你们可以随便创建若干个字段

3、刷新后台界面

4、进入表单管理处,录入一些测试数据

{xunruicms_img_title}


-----------这个时候是关键部分,需要开发了----------


5、找到表单前端控制器文件/dayrui/App/Form/Controllers/Zhengshu.php

<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时可以修改本文件,不影响升级覆盖
 */

class Zhengshu extends \Phpcmf\Home\Form
{

    public function index() {
        $this->_Home_List();
    }

    public function show() {
        $this->_Home_Show();
    }

    public function post() {
        $this->_Home_Post();
    }

    public function search() {

        // 接收url传递的值
        $title = dr_safe_replace(\Phpcmf\Service::L('input')->get('title'));
        $zsbh = dr_safe_replace(\Phpcmf\Service::L('input')->get('zsbh'));
        if (!$title) {
            $this->_msg(0, '证书名称不能为空');
        }
        if (!$zsbh) {
            $this->_msg(0, '证书编号不能为空');
        }

        // 查询
        $row = \Phpcmf\Service::M()->table($this->init['table'])->where('title', $title)->where('zsbh', $zsbh)->getRow();
        if (!$row) {
            $this->_msg(0, '没有查询到');
        }

        // 查询到了调转到表单详情页面
        $url = SITE_URL.'index.php?s=form&c='.$this->form['table'].'&m=show&id='.$row['id'];

        dr_redirect($url);
    }

}


6、然后在任意页面组建一个表单搜索窗口,比如我随便在首页写一个 

xunruicms/template/pc/default/home/index.html

<form class="search-form" action="/index.php" method="get">
    <input type="hidden" name="s" value="form">
    <input type="hidden" name="c" value="zhengshu">
    <input type="hidden" name="m" value="search">

    证书名称:<input type="text"  name="title" >
    证书编号:<input type="text"  name="zsbh" >
    <button class="btn default" type="submit"> 查询 </button>

</form>


然后访问这个模板的url,看到效果

{xunruicms_img_title}

代码比较简单,需要开发者后期自己美化form体内。


7、尝试搜索名称+编号,看看结果

{xunruicms_img_title}


8、搜索结果会调转到表单详情界面上,如下

{xunruicms_img_title}

具体开发者可以在【开发者模式下】看到本页面的具体模板路径,改改显示方式,把后台的自定义字段都调用出来!


完成搜索流程


----------如果要实现只搜索【证书】,只需要把(5)中代码稍微改一下----

/dayrui/App/Form/Controllers/Zhengshu.php

<?php namespace Phpcmf\Controllers;

/**
 * 二次开发时可以修改本文件,不影响升级覆盖
 */

class Zhengshu extends \Phpcmf\Home\Form
{

    public function index() {
        $this->_Home_List();
    }

    public function show() {
        $this->_Home_Show();
    }

    public function post() {
        $this->_Home_Post();
    }

    public function search() {

        // 接收url传递的值
        $zsbh = dr_safe_replace(\Phpcmf\Service::L('input')->get('zsbh'));
        if (!$title) {
            $this->_msg(0, '证书名称不能为空');
        }

        // 查询
        $row = \Phpcmf\Service::M()->table($this->init['table'])->where('zsbh', $zsbh)->getRow();
        if (!$row) {
            $this->_msg(0, '没有查询到');
        }

        // 查询到了调转到表单详情页面
        $url = SITE_URL.'index.php?s=form&c='.$this->form['table'].'&m=show&id='.$row['id'];

        dr_redirect($url);
    }

}

搜索表单的from里面也可以把多余的搜索框去掉!

完成搜索方案

文档最后更新时间:2020-11-16 08:33:33
我来修改此文档(1) 不会操作怎么办?