Model Save From $_Get

If am getting the data from $_GET. Do I need to create any special validators in my model? I only have the default rules.

// Create Registration Event

$regEvent = new RegEvent;

$regEvent->email = $_GET['email'];

$regEvent->cid = $_GET['cid'];

$regEvent->date = $_GET['date'];

$regEvent->classification = $_GET['classification'];

$regEvent->score = $_GET['score'];

$regEvent->sent_to = $_GET['sent_to'];

$regEvent->description = $_GET['description'];

if(!$regEvent->save()) {

  $pass = FALSE;

  Yii::log('Failed to save RegEvent ' . $url, 'error', 'api');

  $this->_sendResponse(501, sprintf('Error: Registration Event did not save correctly!'));



Validator execution is governed by scenario, not assignment source. The model has no way of "knowing" where the values came from.

Is there a reason you’re not using massive assignment? By assigning them individually your ‘safe’ assignment rules WILL BE IGNORED. Something like $model->attributes = $_GET[‘ClassName’] is preferable to what you’re doing if you can swing it.

In any case, it’s not considered good practice to do resource modification using GET. The GET HTTP method means “retrieve the resource”. If you’re creating or editing a resource try using POST or PUT.

I am creating a simple API that allows someone to add data to the database via URL like this:


I use $_GET to get the values? You think this is bad? What way would you recommend?

Enjoy: APIgee’s API Best Practice’s Blog. :)

Lots of great tips and reading there.

If you’re dealing with developers (and with an API you must be, right?) I would use GET and POST methods to differentiate between getting data and adding new data to the database. Eg:

GET - retrieves a list of people

POST - adds a new person to the database

GET - retrieves person with ID 1

POST - Update the person with ID 1

Others might recommend support for the PUT and DELETE methods, but DELETE is relatively unknown and I don’t think many will care about the POST/PUT distinction.

See also the new Paypal API docs for some good examples.