<?php
namespace app\models;
use yii\db\ActiveRecord;
use yii;
use yii\base\Model;
class Blog extends ActiveRecord{
public static function tableName(){
return 'blog';
}
public function getCategory(){
return $this->hasOne(Blog::className(), ['id' => 'id']);
}
}
class BlogForm extends Model
{
public $nick ;
public $email;
public $body;
public $page;
/**
* @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 static function tableName(){
return 'blogform';
}
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, page)' .
' VALUES (\'' . $nickSafe . '\', REPLACE("' . $bodySafe . '", "\n", "<br />"));')->execute();
return true;
}
return false;
}
}
<?php
$provider = new ArrayDataProvider([
'allModels' => $comments,
'pagination' => [
'pageSize' => 10,
]
]);
echo $product['id']; // здесь значение получается
echo ListView::widget([
'dataProvider' => $provider,
'itemView' => function ($model, $key, $index, $widget) {
echo $i;
if($model['page'] == $product['id']) //Как получить здесь значение?
if ($model['email']) {
return $this->renderDynamic('echo \'<b>' . $model['nick'] . '</b> (' . $model['email'] . '):<br>' . $model['body'] . '<br><br>\';');
} else {
return $this->renderDynamic('echo \'<b>' . $model['nick'] . '</b>:<br>' . $model['body'] . '<br><br>\';');
}
},
'emptyText' => 'Отзывов нет, будьте первым! '
])
?>
</div>
</div>
представление
контроллер