I’m using uploadify to upload documents and and using Yii’s form handling on the backend. Here’s my current code:
if (Yii::app()->getRequest()->getIsPostRequest()) {
$json = [];
$form = new \InstaLabel\Models\Forms\TemplateUpload();
if (!$form->validate()) {
header('HTTP/1.1 500 Internal Server Error', true, 500);
$json['errors'] = $form->getErrors();
}
echo json_encode($json);
return Yii::app()->end();
}
I’m running into an issue where my application’s debug information is being sent in addition to the ajax. I can just use exit() to prevent this, but I’d rather have a proper shutdown of the application. I’m not able to find a clear answer on this.
I don’t know if I fully understand you question and if this will solve your problem.
I think you can use afterValidate method of the CActiveForm. if this method returns false, it stops sending the normal request form then you can do an ajax request in this method. Then you don’t need to do:
header(‘HTTP/1.1 500 Internal Server Error’, true, 500);
I know this is old but still to save someone some time:
I use in the controller before the end of ajax call:
foreach (Yii::app()->log->routes as $route)
if ($route instanceof CWebLogRoute)
$route->enabled=false;
Yii::app()->end();
This stops CWebLogRoute from adding debug info (like system.db.CDbCommand) at the end of json output, but still allows CFileLogRoute to save Yii::log() in ajax calls