Ordering paginate in Cakephp

Asked

Viewed 56 times

0

I’ve never heard of Cakephp, I’m having a little trouble adjusting a purchased script where the developer doesn’t support it.

This code is responsible for listing some records of images saved in the database.

        public function choose(Request $request)
        {
            $memes = $this->meme->paginate(10000);

            if ($request->has('ajax')) {
                return $this->jsonPagination($memes, view('ext-meme::partials.memes', compact('memes')));
            }

            return view('ext-meme::choose', compact('memes'));
        }

They are listed in ascending order according to what they were inserted into the bank.

What would the code look like to list in reverse order? The last records being displayed first.

  • What is the code of the $this->meme->paginate function? Is cakephp2 or 3?

1 answer

0

To sort decreasing use the 'DESC' and to list from top to bottom use the 'ASC'.

    public function choose(Request $request)
    {
        $memes = $this->meme->paginate(10000)->order(['nomeColuna' => 'ASC']);;

        if ($request->has('ajax')) {
            return $this->jsonPagination($memes, view('ext-meme::partials.memes', compact('memes')));
        }

        return view('ext-meme::choose', compact('memes'));
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.