Help me to understand how buttons now work

Open to all! Ask other shopowners for help.
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Help me to understand how buttons now work

Post 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') . '&nbsp;' . 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


Join The Code Co-op to get access to your library in the Code Co-op Forum
User avatar
Kofod95
Senior Contributor
Posts: 748
Joined: Sat Feb 06, 2021 7:38 pm
Phoenix Version: 1.0.8.20
Has thanked: 99 times
Been thanked: 179 times

Re: Help me to understand how buttons now work

Post 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
I'm not smart, but sometimes even a blind chicken can find a corn.
Here are a lot of corns: Phoenix user guide
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Help me to understand how buttons now work

Post 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)),
  '&nbsp;',
  new Button(IMAGE_BUTTON_SAVE, 'fa fa-floppy-o', 'btn-success')
?>
maybe?
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: Help me to understand how buttons now work

Post 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

Code: Select all

phoenix_normalize($parameters)
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Help me to understand how buttons now work

Post 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.
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: Help me to understand how buttons now work

Post 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.
raiwa
Certified Developer
Posts: 1641
Joined: Sat Dec 21, 2019 8:08 am
Phoenix Version: 1.1.0.6
Has thanked: 70 times
Been thanked: 152 times

Re: Help me to understand how buttons now work

Post by raiwa »

See the link in my footer:
Public Phoenix Change Log Cheat Set on Google Sheets
Public Phoenix Change Log Cheat Set on Google Sheets
https://docs.google.com/spreadsheets/d/ ... sp=sharing

Need Help?viewtopic.php?f=10&t=27
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: Help me to understand how buttons now work

Post 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
<a class="btn btn-primary" href="http://partsfinderpro/admin/parts_categ ... w_category" id="btn1">New Category</a>
Somehow extra characters are in generated in the link %3D0%26

Not sure if this is causing the button not to work?
ecartz
Core Team
Posts: 3084
Joined: Tue Nov 05, 2019 6:02 pm
Phoenix Version:
Has thanked: 4 times
Been thanked: 208 times

Re: Help me to understand how buttons now work

Post by ecartz »

Code: Select all

['parent_id' => $parent_id, 'parts_category_id' => $parts_category_id, 'action' => 'new_category']
User avatar
tessthepup
Certified Developer
Posts: 383
Joined: Mon Mar 01, 2021 5:55 pm
Phoenix Version:
Has thanked: 47 times
Been thanked: 62 times

Re: Help me to understand how buttons now work

Post 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')


Join The Code Co-op to get access to your library in the Code Co-op Forum
Post Reply