Git Product home page Git Product logo

Comments (6)

poetbi avatar poetbi commented on August 16, 2024

如果两个动作代码相似度较大,可以写成一个动作,通过某个参数来区分。

建议安装DEMO,查看里面的示例用法

from boaphp.

ziqiming avatar ziqiming commented on August 16, 2024

刚看了DEMO,,确实比以前的DEMO写的详细多了。
验证器的验证规则,好多文件都有USER的相关验证。。重复的太多啦。最好还是出一个通用验证的文件
比如通用参数 ID USER PASS 等等,设置以后,不管这个参数在哪个动作使用,都可以验证它。这样更简单

from boaphp.

poetbi avatar poetbi commented on August 16, 2024

后续我考虑如何方便的实现,目前可以这么做,在一个验证规则文件里包含另一个公共验证规则:

<?php

$common = include('../common.php'); // 一个公共验证规则

$arr = ['...']; // 当前验证规则,去除公共重复的部分

$arr = array_merge($common, $arr); // 合并验证规则

return $arr; // 这里要返回数组

?>

from boaphp.

ziqiming avatar ziqiming commented on August 16, 2024

这个解决办法好粗暴,,,,比如这样的

默认是这个规则
'id' => [
'label' => 'ID', 'check' => 'is_alnum'
],

在某些文件ID为必填写的
要改为

'id' => [
'label' => 'ID', 'check' => 'required&is_alnum'
],

用这个方法还行吗?

from boaphp.

poetbi avatar poetbi commented on August 16, 2024

我不知道你的id什么类型,如果整型不要这么做的,如果是字符串直接用is_alnum就可以了(检测是否字母或数字),空值肯定不通过,具体可以用如下方法测试下结果:

$check = new \boa\validater\checker();

$res = $check->is_alnum($id);

var_dump($res);

from boaphp.

poetbi avatar poetbi commented on August 16, 2024

后续出个规则测试工具

from boaphp.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.