惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
D
Docker
Martin Fowler
Martin Fowler
人人都是产品经理
人人都是产品经理
GbyAI
GbyAI
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
M
MIT News - Artificial intelligence
腾讯CDC
阮一峰的网络日志
阮一峰的网络日志
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
Blog — PlanetScale
Blog — PlanetScale
Vercel News
Vercel News
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
I
InfoQ
U
Unit 42

博客园 - hikoming

Privacy Policy for Hurry Pee PhotoTool Compress/Remove EXIF Privacy Policy for PhotoTool Compress/Remove EXIF Privacy Policy for Units Converter Pro7 Units Converter Pro7 - Convert Any Unit Privacy Policy for DigitalPet DigitalPet-Tamagotchi in watch Privacy Policy for DiceRoll 3D DiceRoll on watch two dice 无痕换字(TextGhost) 隐私政策 无痕改字-AI智能替换 Privacy Policy for EasyCalc EasyCalc: Calculate Anything, Effortlessly.* 让 go build 生成的可执行文件对 Mac、linux、Windows 平台一致 关于html5调用手机相机(原创) (iOS)开发中收集的小方法 (iOS)关于@property和@synthesize的理解(原创) 我的iOS-App Xcode的Architectures、Valid Architectures和Build Active Architecture Only属性(原创) IOS设备型号(原创)
yii2-验证规则,rules,判断条件
hikoming · 2017-04-07 · via 博客园 - hikoming

yii2模型的验证规则,简单的使用我就不详细说了,想看的可以去看
官网教程
http://www.yiichina.com/doc/guide/2.0/structure-models#validation-rules
社区网友教程
http://www.yiichina.com/topic/6420
这里我想说一下,rules规则里面,加判断条件的情况
举个例子,比如我想实现两个字段至少有一个是必填的条件,这时就需要在required里面加判断条件了,
之前查资料国内文档都没有写如何做,laravel框架有required_without来判断
后来在stackoverflow上找到了可以加when和whenclient条件,上面网友教程也提到了,这是我在Google上找到相关信息后,
又来百度查,只找到这一篇,但是相关内容写的不详细。
when 代表服务器端的判断条件,生效条件。
whenclient 代表是客户端的判断条件,js生效条件。
以下是我的代码,仅供参考

            [
                'executor_id',
                'required',
                'when' => function ($model) {
                    return empty($model->doctor_id);
                },
                'whenClient' => "function (attribute, value) {
                    return $('#doctor_id').value == '';
                }",
                 'on' => 'assgin',
            ],
            [
                'doctor_id',
                'required',
                'when' => function ($model) {
                    return empty($model->executor_id);
                },
                'whenClient' => "function (attribute, value) {
                    return $('#executor_id').value == '';
                }",
                'on' => 'assgin',
            ]        

总结:掌握高超了搜索技术对于查找所需知识是非常重要的啊