How Do You Valid $_Get And $_Post ?

How do you valid $_GET and $_POST ?

For example: GET [id] has not been received. The script has no sense anymore. How must I valid them?

It depends on your business logic.

For example, you can use required named action param, so "400 bad request" will be generated.

public action actionView($id)




Or you can raise 404 if ou want.

Well. If I want to valid an ajax request. For example to vote, to send a comment:

vote GET params: article_id (required), value (required)

comment GET params: article_id (required), text (required), your_name (NOT required)

I need to show a json message {"error":true;"message":"article_id is empty"} if there was an error.

I thought about nice thing similar CActiveRecord rules()

Stick to the validation rules you applied to your models.

If you’re doing some custom ajax requests, you could probably parse the errors put out by your model by looking at $model->getErrors().