public function actionSetdriverlocation() { if (!isset($_REQUEST['user_id']) || !isset($_REQUEST['lat']) || !isset($_REQUEST['long'])) { echo CJSON::encode($this->statusError('Check your parameters')); Yii::app()->end(); } $driver = Driver::model()->findByPk($_REQUEST['user_id']); if ($driver == null) { echo CJSON::encode($this->statusError('User not found')); } $driverLocation = new DriverLocation(); $driverLocation->driver_user_id = $_REQUEST['user_id']; $driverLocation->time = time(); $driverLocation->lat = $_REQUEST['lat']; $driverLocation->long = $_REQUEST['long']; if ($driverLocation->save()) { echo '1'; } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = DriverLocation::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }