Advertisement
Nass07

FactoryController

Mar 24th, 2015
3,274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace backend\modules\master\controllers;
  4.  
  5. use Yii;
  6. use backend\modules\master\models\Factory;
  7. use backend\modules\master\models\FactorySearch;
  8. use yii\web\Controller;
  9. use yii\web\NotFoundHttpException;
  10. use yii\filters\VerbFilter;
  11.  
  12. /**
  13.  * FactoryController implements the CRUD actions for Factory model.
  14.  */
  15. class FactoryController extends Controller
  16. {
  17.     public function behaviors()
  18.     {
  19.         return [
  20.             'verbs' => [
  21.                 'class' => VerbFilter::className(),
  22.                 'actions' => [
  23.                     'delete' => ['post'],
  24.                 ],
  25.             ],
  26.         ];
  27.     }
  28.  
  29.     /**
  30.      * Lists all Factory models.
  31.      * @return mixed
  32.      */
  33.     public function actionIndex()
  34.     {
  35.         $searchModel = new FactorySearch();
  36.         $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
  37.  
  38.         return $this->render('index', [
  39.             'searchModel' => $searchModel,
  40.             'dataProvider' => $dataProvider,
  41.         ]);
  42.     }
  43.  
  44.     /**
  45.      * Displays a single Factory model.
  46.      * @param integer $id
  47.      * @return mixed
  48.      */
  49.     public function actionView($id)
  50.     {
  51.         return $this->render('view', [
  52.             'model' => $this->findModel($id),
  53.         ]);
  54.     }
  55.  
  56.     /**
  57.      * Creates a new Factory model.
  58.      * If creation is successful, the browser will be redirected to the 'view' page.
  59.      * @return mixed
  60.      */
  61.     public function actionCreate()
  62.     {
  63.         $model = new Factory();
  64.  
  65.         if ($model->load(Yii::$app->request->post()) && $model->save()) {
  66.             $model->refresh();
  67.             Yii::$app->response->format = 'json';
  68.             return $this->redirect('index');
  69.         } else {
  70.             return $this->renderAjax('create', [
  71.                 'model' => $model,
  72.             ]);
  73.         }
  74.     }
  75.  
  76.     /**
  77.      * Updates an existing Factory model.
  78.      * If update is successful, the browser will be redirected to the 'view' page.
  79.      * @param integer $id
  80.      * @return mixed
  81.      */
  82.     public function actionUpdate($id)
  83.     {
  84.         $model = $this->findModel($id);
  85.  
  86.         if ($model->load(Yii::$app->request->post()) && $model->save()) {
  87.             return $this->redirect(['view', 'id' => $model->id]);
  88.         } else {
  89.             return $this->render('update', [
  90.                 'model' => $model,
  91.             ]);
  92.         }
  93.     }
  94.  
  95.     /**
  96.      * Deletes an existing Factory model.
  97.      * If deletion is successful, the browser will be redirected to the 'index' page.
  98.      * @param integer $id
  99.      * @return mixed
  100.      */
  101.     public function actionDelete($id)
  102.     {
  103.         $this->findModel($id)->delete();
  104.  
  105.         return $this->redirect(['index']);
  106.     }
  107.  
  108.     /**
  109.      * Finds the Factory model based on its primary key value.
  110.      * If the model is not found, a 404 HTTP exception will be thrown.
  111.      * @param integer $id
  112.      * @return Factory the loaded model
  113.      * @throws NotFoundHttpException if the model cannot be found
  114.      */
  115.     protected function findModel($id)
  116.     {
  117.         if (($model = Factory::findOne($id)) !== null) {
  118.             return $model;
  119.         } else {
  120.             throw new NotFoundHttpException('The requested page does not exist.');
  121.         }
  122.     }
  123.  
  124.     public function actionLists($id)
  125.     {
  126.          echo "<pre>";print_r($id);die;
  127.          $countPosts = \backend\modules\master\models\Factory::find()
  128.          ->where(['id_company' => $id])
  129.          ->count();
  130.  
  131.          $posts = \backend\modules\master\models\Factory::find()
  132.          ->where(['id_company' => $id])
  133.          ->orderBy('id DESC')
  134.          ->all();
  135.  
  136.          if($countPosts> 0)
  137.          {
  138.          foreach($posts as $post){
  139.             echo "<option value='".$post->id."'>".$post->factory."</option>";
  140.             }
  141.          }
  142.          else{
  143.          echo "<option>-</option>";
  144.          }
  145.  
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement