Comments (6)
如果两个动作代码相似度较大,可以写成一个动作,通过某个参数来区分。
建议安装DEMO,查看里面的示例用法
from boaphp.
刚看了DEMO,,确实比以前的DEMO写的详细多了。
验证器的验证规则,好多文件都有USER的相关验证。。重复的太多啦。最好还是出一个通用验证的文件
比如通用参数 ID USER PASS 等等,设置以后,不管这个参数在哪个动作使用,都可以验证它。这样更简单
from boaphp.
后续我考虑如何方便的实现,目前可以这么做,在一个验证规则文件里包含另一个公共验证规则:
<?php
$common = include('../common.php'); // 一个公共验证规则
$arr = ['...']; // 当前验证规则,去除公共重复的部分
$arr = array_merge($common, $arr); // 合并验证规则
return $arr; // 这里要返回数组
?>
from boaphp.
这个解决办法好粗暴,,,,比如这样的
默认是这个规则
'id' => [
'label' => 'ID', 'check' => 'is_alnum'
],
在某些文件ID为必填写的
要改为
'id' => [
'label' => 'ID', 'check' => 'required&is_alnum'
],
用这个方法还行吗?
from boaphp.
我不知道你的id什么类型,如果整型不要这么做的,如果是字符串直接用is_alnum就可以了(检测是否字母或数字),空值肯定不通过,具体可以用如下方法测试下结果:
$check = new \boa\validater\checker();
$res = $check->is_alnum($id);
var_dump($res);
from boaphp.
后续出个规则测试工具
from boaphp.
Related Issues (14)
- 新八本5.4,视图输出json的BUG HOT 1
- 如何清理已经过期的缓存文件 HOT 5
- 请问boa::db()->execute($sql)这个写法sql语句可以注入吗? HOT 1
- 预处理数据在model中无法使用吗? HOT 3
- 问一个model操作数据库的效率问题 HOT 1
- 关于mysql数据库插入的一个使用 HOT 3
- 关于JSON的输出配置 HOT 9
- 关于数据库配置参数的缺省值问题 HOT 1
- 关于上传upload方法 HOT 5
- $this->request的使用问题 HOT 9
- 有没有视频处理的相关方法? HOT 2
- 自定义了一个验证方法,语言包的识别ID怎么配 HOT 3
- boaServer 开发环境 PHP配置问题 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from boaphp.