View previous topic :: View next topic |
Author |
Message |
Alpha_Numeric Smarty Rookie
Joined: 18 Aug 2008 Posts: 6
|
Posted: Mon Oct 20, 2008 9:46 pm Post subject: |
|
|
Celeb
Sorry for the delay in responding. I am sure I click the 'Notify me when a reply is posted' but don't seem to be seeing the notice. Perhaps my SPAM filter -I will check.
I made the change to the file. Taking out:
Code: | $smarty->register_modifier( "sortby", "smarty_modifier_sortby" ); |
It makes no difference to the result of course.
The issue is, the array never sorts, it doesn't seem to matter what I try and place as an argument to sortby. I have error_reporting 6143 turned on and all. It doesn't throw an error, it simply doesn't sort.
Is there someway for me to provide better input in helping the forum community help me? |
|
Back to top |
|
Alpha_Numeric Smarty Rookie
Joined: 18 Aug 2008 Posts: 6
|
Posted: Tue Oct 21, 2008 3:07 am Post subject: |
|
|
Celeb
Sorry for wasting your time on this one. It was a programming error, so simple I did not see it.
The function was re-ordering the array, but the code:
Code: | assign var=id value=$smarty.foreach.Tickets.index}
{assign var=ticket value=$Tickets.$id} |
Is using the index (which remains true to the re-ordered data set) to output the array entries in their original order, not re-sorted order.
Oops. |
|
Back to top |
|
douglaskarr Smarty n00b
Joined: 05 Jan 2010 Posts: 1
|
Posted: Tue Jan 05, 2010 4:21 pm Post subject: Error |
|
|
I get an error as well:
Code: | Fatal error: Cannot use object of type MDB2_BufferedResult_mysql as array in modifier.sortby.php(34) : runtime-created function on line 1 |
|
|
Back to top |
|
fl3x7 Smarty Rookie
Joined: 12 Feb 2011 Posts: 8
|
Posted: Wed Feb 16, 2011 9:29 am Post subject: |
|
|
Hope someone can help. Im just trying to order a simple array. No keys specified eg
Array ( [0] => 100[1] => 50[2] => 75)
I would just like to sort the above smallest first. Normally I would use one of the php sort functions but I need to do this in the smarty template.
Ive added the plugin and have the following code so far:
Code: | {assign var='myarray' value=','|explode:"100,50,75"}
{foreach from=$myarray item=i nocache}
{$i}
{/foreach}
|
Everytime i add the sortby like this:
Code: |
{foreach from=$myarray|@sortby:"#" item=i nocache} |
I get the error:
Fatal error: Call to a member function register_modifier() on a non-object in xxxx\smarty\libs\plugins\modifier.sortby.php on line 51
Im pretty new to smarty so any help would be appreciated
Thanks a lot |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Feb 16, 2011 2:56 pm Post subject: |
|
|
What does modifier.sortby.php look like? |
|
Back to top |
|
fl3x7 Smarty Rookie
Joined: 12 Feb 2011 Posts: 8
|
Posted: Wed Feb 16, 2011 3:08 pm Post subject: |
|
|
thanks for your reply.
The modifier.sortby.php was the one posted by pscsuk on the first page.
However I have now just created a new simple function and all seems to be well (first time ive ever used custom functions in smarty woo)
thanks a lot |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Wed Feb 16, 2011 3:17 pm Post subject: |
|
|
I tried this and it worked:
Code: | {$data|@sort:$smarty.const.SORT_NUMERIC}
{foreach from=$data item="foo"}
{$foo}
{/foreach} |
the php "sort" function sorts an array in-place, so this won't work in-line with the foreach loop. you have to sort first, then loop it. |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Feb 16, 2011 3:21 pm Post subject: |
|
|
The originally posted modifier.sortby.php did contain an unneeded/unwanted $smarty->register_modifier( "sortby", "smarty_modifier_sortby" ); which should be removed. This was also discussed in this thread befor. |
|
Back to top |
|
jaze22 Smarty Rookie
Joined: 06 Jan 2010 Posts: 6
|
Posted: Fri Mar 29, 2013 3:50 pm Post subject: |
|
|
Who can modify the sortby plugin to work with a timestamp?
order by date sortby views
Date in the array is currently a unix timestamp and it won't sort because of it. |
|
Back to top |
|
programmining Smarty Rookie
Joined: 18 Oct 2012 Posts: 6
|
Posted: Wed Jun 12, 2013 2:25 pm Post subject: |
|
|
Hey all. Using Smarty-3.1.13 - does the sortby modifier still work in this version - or - was this script update included for it?
Update to the link previously posted on page one about variable modifiers (notice how sort doesn't exist):
http://www.smarty.net/docsv2/en/language.modifiers
Thanks,
pmmg |
|
Back to top |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Wed Jun 12, 2013 6:51 pm Post subject: |
|
|
The sortby modifier discussed here is not included in the Smarty distribution, it's a custom implementation.
It should work also with 3.1 but it's not tested. |
|
Back to top |
|
programmining Smarty Rookie
Joined: 18 Oct 2012 Posts: 6
|
Posted: Wed Jun 12, 2013 7:23 pm Post subject: |
|
|
Thanks U.Tews.
For our team, our Dev's are pushing hard to keep this out of the templates. Already other projects have moved towards json & js templating systems so from a processes and technology perspective it makes sense for us to keep it out.
As much as I'd like to provide the client with a cheaper price point for this functionality by doing it on the Front End, I can't find any justifications.
Do any of you have any?
Thanks,
pmmg |
|
Back to top |
|
cole Smarty n00b
Joined: 23 Jan 2019 Posts: 1
|
Posted: Wed Jan 23, 2019 12:50 am Post subject: |
|
|
Function create_function() is Deprecated in PHP 7.2
Code: | $sort_func = $sort_funcs[$sortby] = create_function('$a, $b', $code); |
Thanks on any help. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sun Jan 27, 2019 6:20 am Post subject: |
|
|
|
|
Back to top |
|
|