CValidator - custom message & placeholders

Hello,

I faced two problems concerning CValidator:

  1. My app is in Russian, so it needs 2 bytes for a letter in strings. Concequently, I have to redouble length max-min limit in CStringValidator.

It works, but user gets something enigmatical error message, because "real" (alphabetical) symbol limit less by half. I tried divide by 2 this {max} placeholder in the message, but unsuccessful. Something looks as

$max = (float)'{max/2}'/2.;

gives zero values in result, but something as

$max = settype(settype('{max}','float'),'string');

throws the error:

Fatal error: Only variables can be passed by reference in Z:\home\dtz.tasks\www\protected\messages\ru\yii.php on line 18

So, does any way exist to transform arithmetically placeholder's value?

  1. I attempted to do something using custom message. I was strongly following instructions, and my rules function is as follows (see the third array - validation 'length' for 'comment' attribute):





<?php


	public function rules()


	{


		return array(


			array('u_init_id, date_change, ref_status_id, customer_id, ref_type_id, ref_terminal_id, ref_object_id, deleted', 'required'),


			array('u_init_id, u_resp_id, ref_status_id, customer_id, ref_terminal_id, ref_type_id, ref_object_id, deleted', 'numerical', 'integerOnly'=>true),


			array('comment','length','max'=>1000, 'message'=>'some test!!!'),


			array('date_plan', 'type', 'type'=>'date', 'dateFormat'=>'yyyy-MM-dd')


		);


	}


?>





I got the old sytem message only, nothing more… Wat's wrong?

Thank you for any help!

  1. You may consider writing a custom validator to handle this. Or enable "mb" PHP extension which may replace strlen() functions with their mb version.

  2. You need to specify "tooLong" and "tooShort" messages.

Quote

1. You may consider writing a custom validator to handle this. Or enable "mb" PHP extension which may replace strlen() functions with their mb version.

I know nothing about this "mb" extension. Could you give me please some reference if possible?

Quote

2. You need to specify "tooLong" and "tooShort" messages.

Thank you! It seems almost obvious - when you’re aware  :)

Sorry it should be mbstring: http://us2.php.net/m…ok.mbstring.php

Oops…

OK, but I still cannot realize, how could it help me to convert string->float->string  ???

What about your other answer - thank you much more! - That is just that I needed in the problem!

I've already learnt. Thanx for your hint!