What's the right syntax for this rule?

Hi, I want to check a code, which is entered by users. I have a field, called 'CODE' in the view,

I assume I have to use some custom validator like this one, for instance.



	 * Check whether code is valid

	 * @param string $code


	public function checkCode($attribute, $params){




I don't know what are these $attribute, $params for.

I am considering the rule something like this, but I can't succeed.

array('CODE', 'checkCode','CODE'),

Any suggestions?

You can ignore these two parameters since your rule is only applied to a single known attribute and you don't specify validation parameters.

Qiang, I added the rule like this:

		array('CODE', 'checkCode'),

My checkCode function looks like this:

public function checkCode($code){


		if(!$code == 1){





I am testing with a fixed string, but I would easy add the logic for CODE. The behavior I want is a check of code. The problem is that I must connect to another site with sockets, and there I will make the check. This is the validation after all. That's why I need a function to handle a request of code from user and to check in the system of the other site whether this code exists there.

What is $code in your validation method? You can simply access the code property via $this->CODE. Also, addError takes two parameters.

Thanks, Qiang, I think I resolved it.