我的前端是Phi Yii。我正在嘗試創建一個自定義驗證規則,檢查數據庫中是否已存在用戶名。自定義驗證規則不適用於CFormModel
我沒有直接訪問數據庫的權限。我必須使用RestClient與數據庫進行通信。我的問題是自定義驗證規則不適用於我的CFormModel。
這裏是我的代碼:
public function rules()
{
return array(
array('name', 'length', 'max' => 255),
array('nickname','match','pattern'=> '/^([a-zA-Z0-9_-])+$/')
array('nickname','alreadyexists'),
);
}
public function alreadyexists($attribute, $params)
{
$result = ProviderUtil::CheckProviderByNickName($this->nickname);
if($result==-1)
{
$this->addError($attribute,
'This Provider handler already exists. Please try with a different one.');
}
這似乎並沒有在所有的工作,我也試過這樣:即使是這樣,它似乎
public function alreadyexists($attribute, $params)
{
$this->addError($attribute,
'This Provider handler already exists. Please try with a different one.');
}
不工作。我在這裏做錯了什麼?