php - Customizing Yii's rule param -


i have following rule:

array('sites_conhecimento_regiao,facilidade_conhecimento_regiao', 'verificaropcoesdousodeinternetconhecimentodaregiao', 'campo'=>'{attribute}'), 

and function calls run validation:

public function verificaropcoesdousodeinternetconhecimentodaregiao($attribute, $params) {     switch ($params['campo']) {         case 'sites_conhecimento_regiao':             $mensagem = 'informe os sites que utilizou para sua pesquisa.';             break;         case 'facilidade_conhecimento_regiao':             $mensagem = 'informe se teve facilidade ao obter informações.';             break;     }      if (isset($this->conhecimento_regiao)) {         if (($this->$attribute === '') && ($this->conhecimento_regiao['conhecimento_regiao_internet'] === '1')) {             $this->adderror($attribute, $mensagem);         }     } } 

i did way reuse condition, core of validation, 2 fields. wish verify field yii calling function. tried using $params, returns string {attribute} instead of replace name of attribute, when setting message in rule.

how can achieve objective?

--

update: although have solved problem (see answer below), if still want solve problem of passing metadata through parameters of rule, leave question opened purpose.

switch ($attribute) { 

an obvious solution...


Comments