Skip to content

Commit

Permalink
addcomments
Browse files Browse the repository at this point in the history
  • Loading branch information
qwest812 committed Feb 2, 2018
1 parent 08ad907 commit cc528be
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 7 deletions.
8 changes: 5 additions & 3 deletions config/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@
],
],
'db' => $db,
/*

'urlManager' => [
'enablePrettyUrl' => true,
'enablePrettyUrl' => false,
'showScriptName' => false,
'rules' => [
'index'=>'site/index',
'pagination'=>'site/pagination'
],
],
*/

],
'params' => $params,
];
Expand Down
28 changes: 28 additions & 0 deletions controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

namespace app\controllers;

use app\models\AddComments;
use app\models\Comments;
use app\models\ContactForm;
use app\models\LoginForm;
use app\models\MyForm;
use app\models\MyForm2;

use Yii;
use yii\data\Pagination;
use yii\filters\AccessControl;
use yii\filters\VerbFilter;
use yii\helpers\Html;
Expand Down Expand Up @@ -197,6 +199,32 @@ public function actionComments(){
['comments'=>$comments]
);
}
public function actionPagination(){
$comments =Comments::find();


$pagination =new Pagination([
'defaultPageSize'=>2,
'totalCount'=>$comments->count(),
]);

$comments=$comments->offset($pagination->offset)
->limit($pagination->limit)
->all();
return $this->render('pagination',
['pagination'=>$pagination,
'comments'=>$comments,
]);
}


public function actionCommentsAdd(){
$model =new AddComments();

return $this->render('addComments',
['model'=>$model]
);
}


}
38 changes: 38 additions & 0 deletions models/AddComments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: PC-1
* Date: 02.02.2018
* Time: 12:22
*/

namespace app\models;

use Yii;
use yii\base\Model;

class AddComments extends Model
{


public $name='';
public $comments='';
public $checkBox='';
public $checkBoxList=array();

public function rules(){
return [
// 'all'=>[['name','text','checkBox'],'required', 'massage'=>'no empty']
];
}
public function attributeLabels()
{
return [
'name' => 'Название',
'comments' => 'Комментарий',
'checkBox' => '',
'checkBoxList' => 'Чекбокс список',
];
}

}
15 changes: 15 additions & 0 deletions views/site/addComments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$form=ActiveForm::begin([
'method'=>'post'
]);
echo $form->field($model,'name')->label('Your Name');
echo $form->field($model,'comments')->textarea(['rows'=>6])->label('Comments');
echo $form->field($model,'checkBox')->checkbox(['value'=>'fff','checked ' => '']);
echo $form->field($model, 'checkBoxList[]')->checkboxList(['a' => 'Item A', 'b' => 'Item B', 'c' => 'Item C',]);
echo Html::submitButton('Add');



ActiveForm::end();?>
8 changes: 4 additions & 4 deletions views/site/form2.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
]);
?>

<?=$f->field($form,'name')->label('Your name')?>
<?=$f->field($form, 'email')->label('Your email')?>
<?=$f->field($form, 'file')->fileInput()?>
<?//=$f->field($form,'name')->label('Your name')?>
<?//=$f->field($form, 'email')->label('Your email')?>
<?//=$f->field($form, 'file')->fileInput()?>

<?= Html::submitButton('Send',['class' => 'btn btn-primary']);?>
<?//= Html::submitButton('Send',['class' => 'btn btn-primary']);?>
<?php ActiveForm::end()?>
18 changes: 18 additions & 0 deletions views/site/pagination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
use yii\widgets\LinkPager;
?>


<h1>Comments</h1>
<?php
foreach($comments as $comment) {?>
<li><b><a href="<?=Yii::$app->urlManager->createUrl(['site/user', 'name'=>$comment->name])?>"><?=$comment->name?></a></b>: <?=$comment->text?></li>

<?php
}

?>
<ul>

<?=LinkPager::widget(['pagination'=>$pagination])?>
</ul>
2 changes: 2 additions & 0 deletions views/site/user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
var_dump($_GET);

0 comments on commit cc528be

Please sign in to comment.