Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. use yiihelpersHtml;
  4. use yiiwidgetsActiveForm;
  5.  
  6. $form = ActiveForm::begin([
  7. 'id' => 'form1',
  8. ]) ?>
  9. <?= $form->field($postForm, 'title') ?>
  10. <?= $form->field($postForm, 'text') ?>
  11. <?= $form->field($postForm, 'userId') ?>
  12.  
  13. <div class="form-group">
  14. <?= Html::submitButton('Добавить', ['class' => 'btn btn-primary']) ?>
  15. </div>
  16. <?php ActiveForm::end() ?>
  17.  
  18. public function actionAdd()
  19. {
  20. $postForm = new Post();
  21.  
  22. if (Yii::$app->request->isAjax) {
  23. $post = new Post();
  24. $post->title = Yii::$app->request->post('title');
  25. $post->text = Yii::$app->request->post('text');
  26. $post->userId = Yii::$app->request->post('userId');
  27. $post->save();
  28.  
  29. if (!$post->save()) {
  30. print_r($post->errors);
  31. }
  32. }
  33.  
  34. return $this->render('addPost', compact('postForm'));
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement