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

推荐订阅源

J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
C
Check Point Blog
G
Google Developers Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
D
Docker
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News

博客园 - 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',
            ]        

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