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

推荐订阅源

H
Help Net Security
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
Google DeepMind News
Google DeepMind News
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
爱范儿
爱范儿
L
LangChain Blog
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog
Hugging Face - Blog
Hugging Face - Blog
G
Google Developers Blog
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
D
DataBreaches.Net
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

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

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