5 replies to this topic
#1
Posted 22 June 2012 - 05:18 AM
First of all, my congratulations to Ryan on this amazing piece of software! This is my first post in these forums, but I have been a silent noob for a few months, learning while using processwire for every web project in the Multimedia Design course I'm currently finishing!
On to the bug/problem (is this the right place for this post?) :
When I try to sort a PageArray object using the $a->sort() method on a string field, say, the title, the API places the ones starting with uppercase first, and the lowercase last, like so: A,B,C,D,a,b,c,d...
Am I doing something wrong/missing something?
Cheers,
Tiago
On to the bug/problem (is this the right place for this post?) :
When I try to sort a PageArray object using the $a->sort() method on a string field, say, the title, the API places the ones starting with uppercase first, and the lowercase last, like so: A,B,C,D,a,b,c,d...
Am I doing something wrong/missing something?
Cheers,
Tiago
#2
Posted 22 June 2012 - 06:10 AM
I can't look it up in the PW code right now but assuming $a->sort is the default php sort it's not a bug. PHP sort function is case sensitive and goes A-Z first and then a-z.
Look at http://php.net/manua...nction.sort.php for more details.
- edit -
https://github.com/r.../Array.php#L657
So ksort and krsort (for reverse)
Maybe it is possible to add options for case-insensitive and natural in the core, something like:
Not sure if Ryan finds it desirable, maybe there are some pitfalls to consider.
Look at http://php.net/manua...nction.sort.php for more details.
- edit -
https://github.com/r.../Array.php#L657
So ksort and krsort (for reverse)
Maybe it is possible to add options for case-insensitive and natural in the core, something like:
uksort($sortable, "strcasecmp"); // case-insensitive uksort($sortable, "strnatcasecmp"); // case-insensitive, natural order algorithm
Not sure if Ryan finds it desirable, maybe there are some pitfalls to consider.
#3
Posted 22 June 2012 - 06:45 AM
sinnut is right, although it's using ksort and krsort. Don't know if there's a way around it. How about if you use the page name for sorting?
@somartist | modules created | support me, flattr my work flattr.com
#5
Posted 22 June 2012 - 10:14 AM
Not tested, but cant't you store your custom sortfield temporary in your pages and sort them later by this field?
Something like this:
EDIT: this code should work:
Something like this:
foreach ($yourpagearray as $p) {
$p->sortfield = toLowerCase($p->title);
}
$yourpagearray->sort("sortfield");
EDIT: this code should work:
foreach ($yourpagearray as $p) {
$p->tempsort = strtolower($p->title);
}
$yourpagearray->sort("tempsort");
Edited by interrobang, 22 June 2012 - 11:49 AM.
#6
Posted 22 June 2012 - 11:09 AM
Yes and no, interrobang
You're right, and I just solved it using your solution... But you seem to have stumbled into a protected field, maybe? Using "sortfield" as a temporary field throws an error, renaming it to something like "mysortfield" makes it work like a charm!
EDIT: so sortfield it's the sort setting for a page's children.
EDIT: so sortfield it's the sort setting for a page's children.
Also tagged with one or more of these keywords: PageArray, sort, issue, API
Community Support →
Getting Started →
No front end css after installStarted by alchime.net, 30 Apr 2013 |
|
|
||
Community Support →
API & Templates →
Using while loop with PW APIStarted by kongondo, 25 Apr 2013 |
|
|
||
Community Support →
General Support →
Select field values not getting edited in front-end formStarted by onjegolders, 23 Apr 2013 |
|
|
||
Community Support →
API & Templates →
$pages->get("/features")->find("field1<field2") possible?Started by jmartsch, 22 Apr 2013 |
|
|
||
Community Support →
General Support →
Creating new repeater items through front-end formStarted by onjegolders, 22 Apr 2013 |
|
|
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













