Validation Help On Code

I been searching and probably keeps on clicking the wrong topic for my problem, so I can’t find the solution. Anyway, I hope you guys could help me on validation.

My controller method approach is to receive via (any of them)

  • url params /users/country/us/user/23

  • GET

  • POST

My questions:

  1. If I receive via url params, is it available via $this->params or something or $this->country?

  2. If I receive via get, is it available via Yii::app()->getRequest() ? can you give a sample?

  3. Assuming those will work, how can I sanitize them? Or it’s automatically been sanitized?

  4. Then, how to do those validation?

I have on my controller code:


$add = new Users();

$add->email = $email;

$add->alias = $alias;


$valid = $add->validate();


if ($valid) {

	$transaction = Yii::app()->db->beginTransaction();


	try {

		$add->save();

		$transaction->commit();

	}

	else {

		$transaction->rollback();

		print_r($add->getErrors());

	}

}

On my model:


public function rules()

 {

     return array(

         array('email', 'length', 'max'=>80),

         array('alias', 'length', 'min'=>3, 'max'=>10),

     );

}

Well the code above does not validate, which is weird. It has the same samples over the web.

Did I missed something? I do not have an overload for beforeSave() on User model.

Help

Sorry. But I found the solution.

It is actually validating. :)

moved print_r($add->getErrors()); on the bottom part. Saw the issue. Alias is short.

Solved!