class Comments extends ActiveRecord
{
public static function tableName()
{
return 'comments';
}
public function rules()
{
return [
/* nick and comment body are both required */
[[ 'body'], 'required'],
];
}
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'body' => Yii::t('app', 'Body'),
'created_at' => Yii::t('app', 'Created At'),
'update_at' => Yii::t('app', 'Update At'),
'status' => Yii::t('app', 'Status'),
];
}
public function behaviors()
{
return [
TimestampBehavior::className(),
];}
}
$comment = new Comments();
$article = Blog::find()->where(['id' => $id])->all();
$query = Comments::find()->where(['page' => $id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
]
]);
if ($comment->load(Yii::$app->request->post()) && $comment->post()) {
return $this->refresh();
}
return $this->render('view', [
'article' => $article,
'dataProvider' => $dataProvider,
'comment' => $comment,
]);
}
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
]) ?>
<?= $form->field($comment, 'body') ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
//'itemView' => 'view',
// 'emptyText' => 'Отзывов нет, будьте первым! ',
])
?>
<section>
<div class="container">
<div class="row">
<div class="col-sm-12 padding-right">
<div class="features_items"><!--features_items-->
<?php if(!empty($article)): ?>
<?php $i = 0; foreach($article as $product): ?>
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<!-- <?= Html::img("@web/images/{$product->img}", ['alt' => $product->header])?> -->
<p style="text-align: justify;"><?= $product->body?></p>
<p ><a href="<?= \yii\helpers\Url::to(['dishes/view', 'id' => $product->id]) ?>"></a></p>
</div>
</div>
<div class="choose">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="comments">
<p >
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
]) ?>
<?= $form->field($comment, 'body') ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => 'view',
'emptyText' => 'Отзывов нет, будьте первым! ',
])
?>
</div>
</div>
<?php endforeach;?>
<?php else :?>
<h2>Здесь статьи пока нет...</h2>
<?php endif;?>
</section>
<section>
<div class="container">
<div class="row">
<div class="col-sm-12 padding-right">
<div class="features_items"><!--features_items-->
<?php if(!empty($article)): ?>
<?php $i = 0; foreach($article as $product): ?>
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<!-- <?= Html::img("@web/images/{$product->img}", ['alt' => $product->header])?> -->
<p style="text-align: justify;"><?= $product->body?></p>
<p ><a href="<?= \yii\helpers\Url::to(['dishes/view', 'id' => $product->id]) ?>"></a></p>
</div>
</div>
<div class="choose">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="comments">
<p >
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
]) ?>
<?= $form->field($comment, 'body') ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => 'view',
'emptyText' => 'Отзывов нет, будьте первым! ',
])
?>
</div>
</div>
<?php endforeach;?>
<?php else :?>
<h2>Здесь статьи пока нет...</h2>
<?php endif;?>
</section><section>
<div class="container">
<div class="row">
<div class="col-sm-12 padding-right">
<div class="features_items"><!--features_items-->
<?php if(!empty($article)): ?>
<?php $i = 0; foreach($article as $product): ?>
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<!-- <?= Html::img("@web/images/{$product->img}", ['alt' => $product->header])?> -->
<p style="text-align: justify;"><?= $product->body?></p>
<p ><a href="<?= \yii\helpers\Url::to(['dishes/view', 'id' => $product->id]) ?>"></a></p>
</div>
</div>
<div class="choose">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="comments">
<p >
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
]) ?>
<?= $form->field($comment, 'body') ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => 'view',
'emptyText' => 'Отзывов нет, будьте первым! ',
])
?>
</div>
</div>
<?php endforeach;?>
<?php else :?>
<h2>Здесь статьи пока нет...</h2>
<?php endif;?>
</section>
<div class="comments">
<p >
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
]) ?>
<?= $form->field($model, 'body') ?>
<div class="form-group">
<div class="col-lg-offset-1 col-lg-11">
<?= Html::submitButton('Отправить', ['class' => 'btn btn-primary']) ?>
</div>
</div>
<?php ActiveForm::end() ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => 'view',
'emptyText' => 'Отзывов нет, будьте первым! ',
])
?>
</div>
</div>
<div class="comments">
<p >
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'post-comment-form',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]); ?>
<?=
$form->field($comment, 'body') ;
var_dump($form) ;
?>
<?php
echo '<div class="form-group">';
echo '<div class="col-lg-11">';
echo Html::submitButton('Отправить', ['class' => 'btn btn-my']);
echo '</div>';
echo '</div>';
?>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => 'view',
'emptyText' => 'Отзывов нет, будьте первым! ',
])
?>
public function actionView($id){
$comment = new Comments();
$article = Blog::find()->where(['id' => $id])->all();
$query = Comments::find()->where(['page' => $id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
]
]);
return $this->render('view', [
'article' => $article,
'dataProvider' => $dataProvider,
'comment' => $comment,
// 'query' => $query,
]);
}
class Comments extends ActiveRecord
{
public $nick ;
public $email;
public $body;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
/* nick and comment body are both required */
[[ 'body'], 'required'],
[['email'], 'email'],
];
}
/**
* Appends post to DB
* @return boolean whether the post is appended successfully
*/
public function post()
{
if ($this->validate()) {
$db = Yii::$app->db;
$nickSafe=Yii::$app->user->identity->email;
$bodySafe = htmlspecialchars($this->body, ENT_QUOTES, "UTF-8");
$db->createCommand('INSERT INTO comments (nick, body)' .
' VALUES (\'' . $nickSafe . '\', REPLACE("' . $bodySafe . '", "\n", "<br />"));')->execute();
return true;
}
return false;
}
}
class Comments extends ActiveRecord
{
public $nick ;
public $email;
public $body;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
/* nick and comment body are both required */
[[ 'body'], 'required'],
[['email'], 'email'],
];
}
/**
* Appends post to DB
* @return boolean whether the post is appended successfully
*/
public function post()
{
if ($this->validate()) {
$db = Yii::$app->db;
$nickSafe=Yii::$app->user->identity->email;
$bodySafe = htmlspecialchars($this->body, ENT_QUOTES, "UTF-8");
$db->createCommand('INSERT INTO comments (nick, body)' .
' VALUES (\'' . $nickSafe . '\', REPLACE("' . $bodySafe . '", "\n", "<br />"));')->execute();
return true;
}
return false;
}
}
<div class="comments">
<p >
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'post-comment-form',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]); ?>
<?php
$field = $form->field($comment, 'body', [
'inputOptions' => [
'placeholder' => $comment->getAttributeLabel('body'),
],
])->label(false);
$field->textArea([
'rows' => '6'
]);
echo $field;
echo '<div class="form-group">';
echo '<div class="col-lg-11">';
echo Html::submitButton('Отправить', ['class' => 'btn btn-my']);
echo '</div>';
echo '</div>';
?>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => function ($comment, $key, $index, $widget) {
if ($comment['email']) {
return $this->renderDynamic('echo \'<b>' . $comment['nick'] . '</b> (' . $comment['email'] . '):<br>' . $comment['body'] . '<br><br>\';');
} else {
return $this->renderDynamic('echo \'<b>' . $comment['nick'] . '</b>:<br>' . $comment['body'] . '<br><br>\';');
}
},
'emptyText' => 'Отзывов нет, будьте первым! '
])
?>
</div>
</div>
public function actionView($id){
$comment = new Comments();
$article = Blog::find()->where(['id' => $id])->all();
$query = Comments::find()->where(['page' => $id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
]
]);
return $this->render('view', [
'article' => $article,
'dataProvider' => $dataProvider,
'comment' => $comment,
'query' => $query,
]);
}
$article = Blog::find()->where(['id' => $id])->all();
<div class="comments">
<p >
<?php Pjax::begin(); ?>
<?php $form = ActiveForm::begin([
'id' => 'post-comment-form',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]); ?>
<?php
$field = $form->field($comment, 'body', [
'inputOptions' => [
'placeholder' => $comment->getAttributeLabel('body'),
],
])->label(false);
$field->textArea([
'rows' => '6'
]);
echo $field;
echo '<div class="form-group">';
echo '<div class="col-lg-11">';
echo Html::submitButton('Отправить', ['class' => 'btn btn-my']);
echo '</div>';
echo '</div>';
?>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</p>
<div class="site-comments">
<h3>Отзывы:</h3>
<?php
$db = Yii::$app->db;
?>
<?php
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemView' => function ($key, $query, $index, $widget) {
if ($comment['email']) {
return $this->renderDynamic('echo \'<b>' . $comment['nick'] . '</b> (' . $comment['email'] . '):<br>' . $comment['body'] . '<br><br>\';');
} else {
return $this->renderDynamic('echo \'<b>' . $comment['nick'] . '</b>:<br>' . $comment['body'] . '<br><br>\';');
}
},
'emptyText' => 'Отзывов нет, будьте первым! '
])
?>
</div>
</div>
public function actionView($id){
$comment = new Comments();
$article = Blog::find()->where(['id' => $id])->all();
$query = Comments::find()->where(['id' => $id]);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
]
]);
return $this->render('view', [
'article' => $article,
'dataProvider' => $dataProvider,
'comment' => $comment,
'query' => $query,
]);
}
почему ничего не выводится, у меня скоро приступ будет))))