I have an Ajax.
How can write this code safer (in controller and view)?
Should I use try-catch? If yes How do it?
$.ajax({
'url': '".$this->createUrl('index')."',
'type': 'post',
'data': {'Id': id,'t': t},
'dataType': 'json',
'success': function(data){},
});
controller:
if (Yii::app()->request->isAjaxRequest) {
if(isset($_POST['id']) && isset($_POST['t'])){
$id = intval($_POST['id']);
$t = intval($_POST['t']);
$ss = Model::model()->findByPk($id);
$result = $ss->data;
echo CJSON::encode(array(
'result' => $result,
));
Yii::app()->end();
}
}
$this->render('index',array(
'model'=>$model,
));