【问题标题】:How to write this yii2 rule?这个yii2规则怎么写?
【发布时间】:2021-07-22 05:16:45
【问题描述】:

目前我有这个规则来检查员工表中的现有 ID。

[['manager_id'], 'exist', 'skipOnError' => false, 'targetClass' => Employee::className(), 'targetAttribute' => ['manager_id' => 'id']]

我有什么办法可以修改此规则以也接受 0 作为有效值,尽管我在此表中没有 ID = 0 的员工?

【问题讨论】:

  • 您可以创建自定义规则,这将允许您执行此任务。

标签: php validation yii2 rules


【解决方案1】:

targetAttribute 值似乎存在问题。你可以试试设置'targetAttribute' => 'id'

[['manager_id'], 'exist', 'skipOnError' => false, 'targetClass' => Employee::className(), 'targetAttribute' => 'id']

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多