yii2-podium
yii2-podium copied to clipboard
Error when trying to render latest message in LatestPosts widget from unknown author
When author of latest post is removed I have this error:
Trying to get property of non-object
in @vendor/bizley/podium/src/views/elements/forum/_forum.php
patch this please in src/views/elements/forum/_forum.php:24 as follow
if (!empty($model->latest) && !empty($model->latest->author) && !empty($model->latest->thread)):
and src/models/Post.php:338
$latest[] = [
'id' => $post->id,
'title' => $post->thread->name,
'created' => $post->created_at,
'author' => $post->author ? $post->author->podiumTag : null,
];
or fix those methods by adding relation check
public static function getLatestPostsForMembers($limit = 5)
{
return static::find()
->joinWith('author', false, 'INNER JOIN')
->orderBy(['created_at' => SORT_DESC])->limit($limit)->all();
}
...
public static function getLatestPostsForGuests($limit = 5)
{
return static::find()
->joinWith('author', false, 'INNER JOIN')
->joinWith(['forum' => function ($query) {
$query->andWhere([Forum::tableName() . '.visible' => 1])->joinWith(['category' => function ($query) {
$query->andWhere([Category::tableName() . '.visible' => 1]);
}]);
}])->orderBy(['created_at' => SORT_DESC])->limit($limit)->all();
}