Page 1 of 2
Help me to understand how buttons now work
Posted: Wed Oct 05, 2022 6:21 pm
by tessthepup
Hi Guys,
I am updating some of my old code from osc2.3.4 to Phoenix and I am a little confused as how admin buttons work these days.
This is the old code
Code: Select all
<?php echo tep_draw_button(IMAGE_GO_BACK, 'fa fa-chevron-left', tep_href_link('parts_category.php', 'parts_category_id='.$parts_category_id.'&parent_id=' . $parent_id), 'primary') . ' ' . tep_draw_button(IMAGE_BUTTON_SAVE, 'fa fa-floppy-o', null, null, null, 'btn-success'); ?>
I have looked at various bits of code but I know I am missing a trick.
Any advice on how buttons work now would help me enormously.
Thanks
Mark
Re: Help me to understand how buttons now work
Posted: Wed Oct 05, 2022 8:28 pm
by Kofod95
From memory:
Name, fa-icon, class, array of parameters, link
So
Code: Select all
<?= new Button(IMAGE_GO_BACK, fa fa-chevron-left', 'primary', [], $GLOBALS['Linker']->build(parts_category.php', ['parts_category_id' => $parts_category_id, 'parent_id' => $parent_id])) ?>
//Daniel
Re: Help me to understand how buttons now work
Posted: Wed Oct 05, 2022 8:36 pm
by ecartz
Code: Select all
<?=
$GLOBALS['Admin']->button(IMAGE_GO_BACK, 'fa fa-chevron-left', 'btn-light', $GLOBALS['Admin']->link('parts_category.php', ['parts_category_id' => $parts_category_id, 'parent_id' => $parent_id)),
' ',
new Button(IMAGE_BUTTON_SAVE, 'fa fa-floppy-o', 'btn-success')
?>
maybe?
Re: Help me to understand how buttons now work
Posted: Thu Oct 06, 2022 6:38 pm
by tessthepup
thank you ecartz
I am now trying to change the form
I have
Code: Select all
<?php echo tep_draw_form('partsfilter', 'parts_products.php', 'action=assign_products&parent_id='.$parent_id.'&parts_category_id='.$parts_category_id.'&page='.(empty($_REQUEST['page'])), 'post');?>
and I tried
Code: Select all
<?= $form = new Form('partsfilter', 'parts_products.php', 'action=assign_products&parent_id='.$parent_id.'&parts_category_id='.$parts_category_id.'&page='.(empty($_REQUEST['page'])), 'post', phoenix_normalize($parameters)); ?>
However this gives me these notices
Notice: Undefined variable: parameters in C:\wamp64\www\partsfinderpro\admin\parts_products.php on line 122
Fatal error: Uncaught TypeError: Argument 4 passed to Form::__construct() must be of the type array, string given, called in C:\wamp64\www\partsfinderpro\admin\parts_products.php on line 122 and defined in C:\wamp64\www\partsfinderpro\includes\system\versioned\1.0.8.1\form.php on line 27
TypeError: Argument 4 passed to Form::__construct() must be of the type array, string given, called in C:\wamp64\www\partsfinderpro\admin\parts_products.php on line 122 in C:\wamp64\www\partsfinderpro\includes\system\versioned\1.0.8.1\form.php on line 27
I am also not sure what this piece of code actually does
Re: Help me to understand how buttons now work
Posted: Thu Oct 06, 2022 10:34 pm
by ecartz
tessthepup wrote: ↑Thu Oct 06, 2022 6:38 pm
Code: Select all
<?= $form = new Form('partsfilter', 'parts_products.php', 'action=assign_products&parent_id='.$parent_id.'&parts_category_id='.$parts_category_id.'&page='.(empty($_REQUEST['page'])), 'post', phoenix_normalize($parameters)); ?>
It expects a link.
Code: Select all
<?= new Form('partsfilter', $GLOBALS['Admin']->link('parts_products.php', ['action' => 'assign_products', 'parent_id' => $parent_id, 'parts_category_id' => $parts_category_id, 'page' => (int)($_REQUEST['page'] ?? 1)])) ?>
You should not need to call phoenix_normalize from code that you write. It's just a shim to convert from the strings that the old code took to the arrays that the new code takes. POST is the default.
Re: Help me to understand how buttons now work
Posted: Fri Oct 07, 2022 5:36 pm
by tessthepup
Thank you again ecartz.
Before I continue to ask annoying questions lol, is there a list anywhere of the deprecated functions and what is used in place now eg. tep_redirect???
ecartz wrote: ↑Thu Oct 06, 2022 10:34 pm
tessthepup wrote: ↑Thu Oct 06, 2022 6:38 pm
Code: Select all
<?= $form = new Form('partsfilter', 'parts_products.php', 'action=assign_products&parent_id='.$parent_id.'&parts_category_id='.$parts_category_id.'&page='.(empty($_REQUEST['page'])), 'post', phoenix_normalize($parameters)); ?>
It expects a link.
Code: Select all
<?= new Form('partsfilter', $GLOBALS['Admin']->link('parts_products.php', ['action' => 'assign_products', 'parent_id' => $parent_id, 'parts_category_id' => $parts_category_id, 'page' => (int)($_REQUEST['page'] ?? 1)])) ?>
You should not need to call phoenix_normalize from code that you write. It's just a shim to convert from the strings that the old code took to the arrays that the new code takes. POST is the default.
Re: Help me to understand how buttons now work
Posted: Fri Oct 07, 2022 5:42 pm
by raiwa
See the link in my footer:
Public Phoenix Change Log Cheat Set on Google Sheets
Re: Help me to understand how buttons now work
Posted: Sun Oct 09, 2022 11:57 am
by tessthepup
moving along very slowly with the conversion.
I have this button
Code: Select all
<?= $GLOBALS['Admin']->button(IMAGE_NEW_CATEGORY, '', 'btn-primary', $GLOBALS['Admin']->link('parts_category.php', ['parent_id=' . $parent_id . '&parts_category_id='.$parts_category_id.'&action=new_category']));?>
Which produces this link
Somehow extra characters are in generated in the link %3D0%26
Not sure if this is causing the button not to work?
Re: Help me to understand how buttons now work
Posted: Sun Oct 09, 2022 12:59 pm
by ecartz
Code: Select all
['parent_id' => $parent_id, 'parts_category_id' => $parts_category_id, 'action' => 'new_category']
Re: Help me to understand how buttons now work
Posted: Sat Oct 15, 2022 5:39 pm
by tessthepup
for the life of me I can not seem to convert correctly the following old buttons
Code: Select all
tep_draw_button(IMAGE_EDIT, 'fa fa-pencil', tep_href_link('parts_category.php', 'parent_id=' . $parent_id . '&parts_category_id=' .$parts_category_id . '&action=edit_category'), 'primary', null, 'btn-warning')
Code: Select all
tep_draw_button(IMAGE_DELETE, 'fa fa-trash-o',tep_href_link('parts_category.php', 'parent_id=' . $parent_id . '&parts_category_id=' . $parts_category_id . '&action=delete_category'), 'primary', null, 'btn-danger')