/** * 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 $id the ID of the model to be loaded * @return ChallanAssignments the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ChallanAssignments::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Manages all models. */ public function actionAdmin() { $model = new Challan('search'); if (!empty($_POST)) { foreach ($_POST['chk'] as $k => $v) { $modelA = new ChallanAssignments(); $modelA->user_id = $_POST['Challan']['user_id']; $modelA->created = date("Y-m-d H:i:s", time()); $modelA->modified = date("Y-m-d H:i:s", time()); $modelA->challan_id = $v; $modelA->assigned_by_user_id = Yii::app()->User->Id; $exist = ChallanAssignments::model()->findAllByAttributes(array("challan_id" => $v)); if (count($exist) == 0) { if ($modelA->save()) { Yii::app()->user->setFlash('success1 message1', "Challan(s) has been assigned successfully"); } else { Yii::app()->user->setFlash('error1 message1', "There was a problem in assignment."); } } // else // { // Yii::app()->user->setFlash('error1 message1', "Challan is already assined."); // } } } $model->unsetAttributes(); // clear any default values if (isset($_GET['Challan'])) { $model->attributes = $_GET['Challan']; } $this->render('admin', array('model' => $model)); }