PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, January 18, 2022

[FIXED] Cakephp 3 paginator sort fields with translate behavior i18n

 January 18, 2022     cakephp-3.0, internationalization, paginator, sorting     No comments   

Issue

I have a Posts table with Translate behavior and I want to sort it by title on the table at index view. I can't sort by the fields that are translated because the field's don't actually exist on the database. They exist on the i18n table.

This, as I explained above, doesn't work:

$this->Paginator->sort('title');
$this->Paginator->sort('Posts_title_translation.content');

So, what I should do? What am I missing?

Many Thanks!


Solution

The second variant should work once the field is being whitelisted, which is generally necessary for associations to be used for sorting:

$this->paginate = [
    // ...
    'sortWhitelist' => [
        'Posts_title_translation.content',
        // ...
    ]
];

Note that with the whitelist in place, you will have to add all other fields of your Posts table that need to be used for sorting too!

See also Cookbook > ... Components > Pagination > Control which Fields Used for Ordering



Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing