Brandonm Posted August 14, 2018 Share Posted August 14, 2018 The @sortby modifier is no longer working with WHMCS 7.6 and PHP 7.2. Does anyone have a way to sort existing Smarty arrays or know how to make @sortby modifier work with the latest version? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 14, 2018 Share Posted August 14, 2018 9 hours ago, Brandonm said: The @sortby modifier is no longer working with WHMCS 7.6 and PHP 7.2. Does anyone have a way to sort existing Smarty arrays or know how to make @sortby modifier work with the latest version? WHMCS v7.6 isn't the problem as it works fine with it - the problem is PHP 7+ and the removal of the "split" function... the simplest solution I can think of is to replace it with explode and the Smarty sortby function will then work fine in v7+ (don't have v7.2 on the dev - but would be surprised if it didn't work with it)... as explode is an old function, I assume the modified file would work in earlier versions of PHP too, but I haven't tested that... i've attached the modified file to this post. for the benefit of others, the file would go in /vendor/smarty/smarty/libs/plugins and can be used to sort arrays in the template... if using older versions of WHMCS (e.g v5), it would go in /includes/classes/Smarty/plugins. it can be used in a number of ways, e.g to sort the $products array alphabetically by name on the opening cart page... {foreach $products|@sortby:"name" as $key => $product} modifier.sortby.php 0 Quote Link to comment Share on other sites More sharing options...
Brandonm Posted August 20, 2018 Author Share Posted August 20, 2018 (edited) Thanks @brian!, apparently my sortby file had a line that was causing an error. Updated with the file you posted and it's working again. Cheers! Edited August 20, 2018 by Brandonm 0 Quote Link to comment Share on other sites More sharing options...
Qhiliqq Posted September 4, 2018 Share Posted September 4, 2018 Hi,, if I use the modifier uploaded by @brian! I get the following error: Error: Cannot use object of type stdClass as array in /vendor/smarty/smarty/libs/plugins/modifier.sortby.php(35) : runtime-created function:1 Stack trace: #0 [internal function]: __lambda_func(Object(stdClass), Object(stdClass)) #1 /vendor/smarty/smarty/libs/plugins/modifier.sortby.php(41): uasort(Array, '\x00lambda_1') #2 /vendor/smarty/smarty/libs/plugins/modifier.sortby.php(49): array_sort_by_fields(Array, 'nick') #3 /var/www/private/data/whmcssecuredata/templates_c/76750c4c25944b213fc954a97e99c8ceddc44f0a_0.file.clientarea.tpl.php(175): smarty_modifier_sortby(Array, 'nick') #4 /vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(122): content_5b8ea1678af145_17819975(Object(Smarty_Internal_Template)) #5 /vendor/smarty/smarty/libs/sysplugins/smarty_template_compiled.php(199): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template)) #6 /vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(159): Smarty_Template_Compiled->render(Object(Smarty_Internal_Template)) #7 /vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(191): Smarty_Internal_Template->render(false, 0) #8 /vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(94): Smarty_Internal_TemplateBase->_execute(Object(Smarty_Internal_Template), NULL, NULL, NULL, 0) #9 /vendor/whmcs/whmcs-foundation/lib/Smarty.php(0): Smarty_Internal_TemplateBase->fetch('/var/www/privat...', NULL, NULL, NULL, false, true, false) #10 /vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): WHMCS\Smarty->fetch('/var/www/privat...') #11 /clientarea.php(0): WHMCS\ClientArea->getSingleTPLOutput('/modules/server...', Array) #12 {main} My foreach: {foreach $instances|@sortby:nick as $instance} The value of $instances: Array (2) 0 => stdClass Object (11) ->nick = "nick1" ->privileges = stdClass Object (0) 1 => stdClass Object (11) ->nick = "nick2" ->privileges = stdClass Object (0) Why I get this error? Regards, Philipp 0 Quote Link to comment Share on other sites More sharing options...
Qhiliqq Posted September 11, 2018 Share Posted September 11, 2018 On 9/4/2018 at 5:19 PM, DAThosting said: Hi,, if I use the modifier uploaded by @brian! I get the following error: Error: Cannot use object of type stdClass as array in /vendor/smarty/smarty/libs/plugins/modifier.sortby.php(35) : runtime-created function:1 Stack trace: #0 [internal function]: __lambda_func(Object(stdClass), Object(stdClass)) #1 /vendor/smarty/smarty/libs/plugins/modifier.sortby.php(41): uasort(Array, '\x00lambda_1') #2 /vendor/smarty/smarty/libs/plugins/modifier.sortby.php(49): array_sort_by_fields(Array, 'nick') #3 /var/www/private/data/whmcssecuredata/templates_c/76750c4c25944b213fc954a97e99c8ceddc44f0a_0.file.clientarea.tpl.php(175): smarty_modifier_sortby(Array, 'nick') #4 /vendor/smarty/smarty/libs/sysplugins/smarty_template_resource_base.php(122): content_5b8ea1678af145_17819975(Object(Smarty_Internal_Template)) #5 /vendor/smarty/smarty/libs/sysplugins/smarty_template_compiled.php(199): Smarty_Template_Resource_Base->getRenderedTemplateCode(Object(Smarty_Internal_Template)) #6 /vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php(159): Smarty_Template_Compiled->render(Object(Smarty_Internal_Template)) #7 /vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(191): Smarty_Internal_Template->render(false, 0) #8 /vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatebase.php(94): Smarty_Internal_TemplateBase->_execute(Object(Smarty_Internal_Template), NULL, NULL, NULL, 0) #9 /vendor/whmcs/whmcs-foundation/lib/Smarty.php(0): Smarty_Internal_TemplateBase->fetch('/var/www/privat...', NULL, NULL, NULL, false, true, false) #10 /vendor/whmcs/whmcs-foundation/lib/ClientArea.php(0): WHMCS\Smarty->fetch('/var/www/privat...') #11 /clientarea.php(0): WHMCS\ClientArea->getSingleTPLOutput('/modules/server...', Array) #12 {main} My foreach: {foreach $instances|@sortby:nick as $instance} The value of $instances: Array (2) 0 => stdClass Object (11) ->nick = "nick1" ->privileges = stdClass Object (0) 1 => stdClass Object (11) ->nick = "nick2" ->privileges = stdClass Object (0) Why I get this error? Regards, Philipp Already fixed via javascript sorting. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.