我在yii2上遇到这个问题请问我如何在列表视图中从一个页面移动到另一个页面“我尝试的所有内容似乎都在起作用。我想要在单击列表视图时将它带到另一个页面并携带单击冒号的数据。到下一页
这是index.php
<?php
use yii\widgets\ListView;
use yii\data\ArrayDataProvider;
use app\models\MyProfile;
use app\models\LikeDiscussion;
use yii\widgets\ActiveForm;
use common\models\Topic;
use yii\widgets\Pjax;
use yii\helpers\Html;
use frontend\assets\AppAsset;
$this->title = 'My Yii Application';
?>
<?php
$query = Topic::find()->all();
$dataArr = array();
foreach ($query as $detail) {
$dataArr[] = array(
'topic_id' => $detail->topic_id,
'topic' => $detail->topic,
'created' => $detail->created,
'creator' => $detail->creator,
'views' => $detail->views
);
}
$dataProvider = new ArrayDataProvider([
'allModels' => $dataArr,
'pagination' => [
'pageSize' => 10,
],
'sort' => [
'attributes' => ['views'=>SORT_ASC]
],
]);
?>
<?php Pjax::begin(['id' => 'countries']) ?>
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'comment-item'],
'itemView' => 'indexadapter',
]);
?>
<?php Pjax::end() ?>
<div class="hr">
</div>
indexadapter
<?php
use yii\helpers\Html;
use yii\helpers\HtmlPurifier;
//var_dump($model);exit;
?>
<div class="gravatar" >
<img src="images/gravatar.png" alt="" >
</div>
<h5><?php echo $model['topic_id'];
?>
</h5>
<p>
<h5>
<span class="commentdate">
<?php echo $model['created']. "by" .$model['creator']; ?>
</span>
</h5>
</p>
<hr>
答案 0 :(得分:1)
试试这个
addAction()