/**
  * Creates a new BlockCode model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new BlockCode();
     if ($model->load(Yii::$app->request->post())) {
         $post = Yii::$app->request->post();
         $categories = $post['BlockCode']['categories'];
         $model->hash_block = md5($post['BlockCode']['name'] . $post['BlockCode']['platform_id'] . rand('100', '1000'));
         if ($model->save()) {
             foreach ($categories as $category) {
                 $block_cat = new CodeblocksAdscategories();
                 $block_cat->adscategory_id = $category;
                 $block_cat->blockcode_id = $model->id;
                 $block_cat->save(false);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'platforms' => Platforms::find()->where(['status' => 2])->all(), 'categories' => Adscategory::find()->all(), 'adstype' => Adstype::find()->all()]);
     }
 }