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:
-
If I receive via url params, is it available via $this->params or something or $this->country?
-
If I receive via get, is it available via Yii::app()->getRequest() ? can you give a sample?
-
Assuming those will work, how can I sanitize them? Or it’s automatically been sanitized?
-
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