Answer the question
In order to leave comments, you need to log in
How to transition between blog posts?
Good afternoon,
The task is to make transitions between posts on a single page. Two buttons next and previous
At the moment I have a transition from fluid to the very first tobish.
previous(1) - current(2) - next(3)
previous(1) - current(3) - next(4)
previous(1) - current(4) - next(5)
previous(1) - current(5) ) - next(6)
and so on.
But how can I fix the code that is in the model, so that it would display the type
previous (1) - current (2) - next (3)
previous (2) - current (3) - next (4)
previous (3) - current (4) - next(5)
previous(4) - current(5) - next(6)
How can I properly sort this whole thing?
code in the model
public static function getNextOrPrevEventPost($id_event,$operator)
{
$data = [];
switch($operator) {
case '<' :
$data = Events::find()
->select('id,title,image')
->where(['<','id',$id_event]);
break;
case '>' :
$data = Events::find()
->select('id,title,image')
->where(['>','id',$id_event]);
break;
}
return $data->one();
}
public function actionView()
{
$getIdEvents = Yii::$app->request->get( 'id' );
$postPaginationEventPrev = Events::getNextOrPrevEventPost($getIdEvents,'<');
$postPaginationEventNext = Events::getNextOrPrevEventPost($getIdEvents,'>');
$getSingleEvent = Events::find()
->where( ['id' => $getIdEvents] )
->all();
return $this->render( 'view', [
'getSingleEvent' => $getSingleEvent,
'postPaginationEventPrev' => $postPaginationEventPrev,
'postPaginationEventNext' => $postPaginationEventNext,
] );
}
Answer the question
In order to leave comments, you need to log in
$before = Blog::find()->select( 'id, title, image' )->where( [ '<', ' id', $this->id] )->orderBy('id DESC')->one();
$after = Blog::find()->select( 'id, title, image' )->where( [ '>', ' id', $this->id] )->orderBy('id ASC')->one();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question