示例#1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new MStock();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['MStock'])) {
         $model->attributes = $_POST['MStock'];
         $model->created_date = time();
         $model->created_by = Yii::app()->user->id;
         if ($model->save()) {
             $model->purchase_date = strtotime($model->purchase_date);
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $products = CHtml::listData(MProduct::model()->findAll(), 'id', 'name');
     $kartons = CHtml::listData(MLitreKarton::model()->findAll(), 'id', 'name');
     $this->render('create', array('model' => $model, 'products' => $products, 'kartons' => $kartons));
 }
 /**
  * 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 = MLitreKarton::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }