| Index
» Projekty
» phpMyEdit
» Fórum
» my workaround for adding customized records buttons |
 |
adler
Založený: 06.01.2011
Príspevky: 5
Zaslal: 2011-01-13 00:48
Návrat hore
Odpovedať s citátom
|
hi,
I'm thinking that maybe someone is searching for a similar solution, so here is a workaround that i figured using some trial and error -
what i wanted is to add in list mode, in each row, next to the regular view/change/copy/delete graphic buttons, my own customized "graphic" button, that will function as a link with GET variables to a different phpMyEdit page. why should i want this? i have SUPPLIERS table, and SUPPRODUCT table, which is a M:N table that details the products for each supplier, and what i wanted is that when the user clicks the customized button of a particular row in the list view of SUPPLIERS phpMyEdit page, the user will be linked to the SUPPRODUCT page, while filtering the latter to view only the records for that particular supplier. the SUPPLIER_ID is ofcourse the key field using which the filteration is made. i needed to find a way to send it in the URL.
enough talking, here is the tweaking i made to the phpMyEdit class in order to:
1. display the button in list view when viewing the SUPPLIERS page.
2. make this button a link to the SUPPRODUCT page with the SUPPLIER_ID in the URL as a GET var (and also the SUPPLIER_NAME as additional GET var).
in the class file, RIGHT AFTER THIS SECTION OF CODE:
| Kód: |
if ($this->delete_enabled()) {
$printed_out && print(' ');
$printed_out = true;
echo '<a class="',$css_class_name,'" href="',$deleteQuery,'"><img class="';
echo $css_class_name,'" src="',$this->url['images'];
echo 'pme-delete.png" height="15" width="16" border="0" ';
echo 'alt="',$deleteTitle,'" title="',$deleteTitle,'" /></a>';
} |
ADD AND CHANGE AS NECESSARY THE FOLLOWING CODE:
| Kód: |
if (basename($_SERVER['PHP_SELF'])=='suppliers.php') { //this makes the custom button show only when viewing suppliers.php
$printed_out && print(' ');
$printed_out = true;
$sName = $this->cellDisplay(2, $row, pme-cell-0); //this is for sending via the URL the supplier name, not only the supplier id. sName holds it. the first argument (2 in my case) tells the code what column to bring the data from. you need to change it according to your table structure.
echo '<a class="',$css_class_name,'" href="',"supproduct.php?sup=$key_rec&supName=$sName",'"><img class="'; //here you see the link's URL and the GET variables. $key_rec holds the key of the pressed record. $sName is the name of the supplier.
echo $css_class_name,'" src="',$this->url['images']; //don't touch.
echo 'gears.png" height="15" width="20" border="0" '; //gears.png is my homemade button.
echo 'alt="View supplier products" title="View supplier products" /></a>'; //set this as you wish.
} |
no special modification is needed in the "father" page. in the "son" page (supproduct.php) add the following:
| Kód: |
<?php
$sup = $_REQUEST['sup']; //DONT FORGET TO SANITIZE THE STRING!
$supName = $_REQUEST['supName']; //DONT FORGET TO SANITIZE THE STRING! ?>
<h3>Parts supplied by <?php echo $supName; ?>:</h3>
//in the phpMyEdit definitions section:
$opts['cgi']['persist'] = array(
'sup' => $sup,
'supName' => $supName); //this maintains the GET variables while moving between different views (add/delete/copy/change/view...) trust me, you need this.
$opts['filters'] = "SUP = $sup"; //to filter the table. this is the point of the whole thing. |
thats it. hope it helps. to me it works perfect, if you don't understand something or need configuration help just leave your comment.
i would also like to thank phpMyEdit creators for this great tool!
adler
|
joeschoe
Založený: 04.05.2009
Príspevky: 9
Zaslal: 2011-06-14 14:41
Návrat hore
Odpovedať s citátom
|
Your code is very useful, thanks.
How could I add a customized navigation button. For example a [Home] button taking me back to the index.php from any screen in phpMyEdit?
|
joeschoe
Založený: 04.05.2009
Príspevky: 9
Zaslal: 2011-06-14 14:42
Návrat hore
Odpovedať s citátom
|
Your code is very useful, thanks.
How could I add a customized navigation button. For example a [Home] button taking me back to the index.php from any screen in phpMyEdit?
|
joeschoe
Založený: 04.05.2009
Príspevky: 9
Zaslal: 2011-06-14 14:42
Návrat hore
Odpovedať s citátom
|
Your code is very useful, thanks.
How could I add a customized navigation button. For example a [Home] button taking me back to the index.php from any screen in phpMyEdit?
|
|
Odoslať novú tému
Odpovedať na tému
|
|
|
|