I want to use loadmore instead of pagination I found this on yii yii2-loadmore when I did try it it doesn’t load page because $model return null I get this error :
Exception 'Error' with message 'Call to a member function getUniqueId() on null'
my controller is :
public function actionIndex()
{
$query = Post::find();
$query->innerJoin('user_follow', 'user_follow.user_id = '.Yii::$app->user->id);
$posts = $query->orderBy(['updated_at'=> SORT_DESC]);
$count = $query->count();
$dataProvider = new ActiveDataProvider([
'query' => $posts,
'pagination' => [
'pageSize' => 24,
],
]);
if (Yii::$app->request->isAjax) {
return $this->renderAjax('@app/humhub/views/activity/index_view', [
'model' => $model,
]);
}
return $this->render('@app/humhub/views/activity/index_list', [
'dataProvider' => $dataProvider,
]);
}
index_list.php
<?php
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;
use yii\widgets\ListView;
use sjaakp\loadmore\LoadMorePager;
echo ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'],
'itemView' => 'index_view',
'pager' => [
'class' => LoadMorePager::class,
'label' => 'Show more data'
],
]);
?>
index_view.php :
<?php
use modules\file\widgets\showFiles\ShowFilesHome;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\LinkPager;
/* @var $this View */
/* @var $header string */
/* @var $content string */
/* @var $footer string */
?>
<div class="wall-entry col-md-2 col-sm-3 col-xs-2">
<div class="panel panel-default wall_<?= $model->getUniqueId() ?>" style="height:570px">
<div class="panel-body">
<div>
<table style="width:100%;padding:5px">
<tr>
<td>
<b><?= $model->title ?></b>
</td>
</tr>
</table>
<hr>
</div>
<div class="wall-entry-body">
<div class="wall-entry-content content" id="wall_content_<?= $model->getUniqueId() ?>">
<?= ShowFilesHome::widget(['object' => $model]); ?>
</div>
</div>
</div>
</div>
</div>