在我的 cakePHP 模型中与 inList 相反的是什么?
What's the opposite of inList in my cakePHP model?
inList
声明您的数组应包含特定的字符串值。
我正在寻找一个规则,该规则将 排除 我模型中名称的某些值。
以下代码规定名称应为 Bob、Bobbie 或 Bobzilla:
'name' => array(
'rule' => array('inList', array('Bob', 'Bobbie', 'Bobzilla')),
'message' => 'Stop it Bob!'
),
我需要用户无法输入这些名称中的任何一个。对我来说,好像 inList
应该是 notInList
。
我尝试了很多方法,但其中 none 把我带到了罗马。
如果你能帮助我,我将不胜感激!
看看PHP in_array函数
像
if (!in_array(ENTERED_NAME,YOUR ARRAY)) {
}
这是我能想到的最佳解决方案:
public function itsBob($check) {
$bobArr = ['Bob', 'Bobbie', 'Bobzilla'];
if (!in_array($check['name'], bobArr) {
return false;
}
return true;
}
在 $validation 中使用以下行:
'name' => array(
'rule' => array('itsBob'),
'message' => 'Stop it bob!'
),
itsBob
字面上与 inList
相反。
inList
声明您的数组应包含特定的字符串值。
我正在寻找一个规则,该规则将 排除 我模型中名称的某些值。
以下代码规定名称应为 Bob、Bobbie 或 Bobzilla:
'name' => array(
'rule' => array('inList', array('Bob', 'Bobbie', 'Bobzilla')),
'message' => 'Stop it Bob!'
),
我需要用户无法输入这些名称中的任何一个。对我来说,好像 inList
应该是 notInList
。
我尝试了很多方法,但其中 none 把我带到了罗马。
如果你能帮助我,我将不胜感激!
看看PHP in_array函数 像
if (!in_array(ENTERED_NAME,YOUR ARRAY)) {
}
这是我能想到的最佳解决方案:
public function itsBob($check) {
$bobArr = ['Bob', 'Bobbie', 'Bobzilla'];
if (!in_array($check['name'], bobArr) {
return false;
}
return true;
}
在 $validation 中使用以下行:
'name' => array(
'rule' => array('itsBob'),
'message' => 'Stop it bob!'
),
itsBob
字面上与 inList
相反。