Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Utorok, 24. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  How to handle a custom field

phpMyEdit Configuration     How to handle a custom field
Odoslať novú tému   Odpovedať na tému    
 
RedBullet     Založený: 02.12.2010   Príspevky: 7  
Príspevok Zaslal: 2010-12-02 14:52
Návrat hore  Odpovedať s citátom     

In my database I am storing structured text as XML in a text field. Essentially it is WDDX that I have serialized.

I am wondering if there is a mechanism in phpMyEdit that lets me process that field appropriately.

I can certainly write my own PHP code to handle the serialization/deserialization easily, just not sure what hooks might exist in phpmyedit.

Thanks in advance!

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2010-12-02 17:19
Návrat hore  Odpovedať s citátom     

See the documentation on using custom PHP scripts, and also Triggers.

http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.fields.php.html#AEN1201

http://opensource.platon.sk/projects/doc.php/phpMyEdit/html/configuration.triggers.html

 
RedBullet     Založený: 02.12.2010   Príspevky: 7  
Príspevok Zaslal: 2010-12-02 18:50
Návrat hore  Odpovedať s citátom     

Yea, I saw that.

So, for a text field that contains serialized data, would I write a php script to de-serialize and use the php opt, but then have to use an update trigger to serialize it back to the DB again?

Or am I not understanding it...

Thanks in advance!

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2010-12-02 18:55
Návrat hore  Odpovedať s citátom     

I fail to grasp the objective. Experiment with triggers, or search the forum for keywords relevant to your objective.

 
RedBullet     Založený: 02.12.2010   Príspevky: 7  
Príspevok Zaslal: 2010-12-02 19:22
Návrat hore  Odpovedať s citátom     

Oh don't give up on me yet! I think you are on the right track!

Basically I am storing some XML in a text field. The XML is essentially structured data for me. For example:

<ride>
<distance>
50 miles
</distance>
<terrain>
hilly
</terrain>
</ride>

And what I want to do is be able to format it when it is being rendered:
ride distance: 50 miles
ride terrain: hilly

Then when they edit the record I would display entry fields for those and then generate the XML to save in the field.

Does that make more sense?

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2010-12-02 22:05
Návrat hore  Odpovedať s citátom     

Design wise, it is a waste of time to store the markup code. Simply store data. Create the markup on-the-fly to surround the bits of data.

Use CONCAT to manipulate record display, and (?) a custom PHP script to create and write an XML file assuming the XML file gets an HTML document.

 
RedBullet     Založený: 02.12.2010   Príspevky: 7  
Príspevok Zaslal: 2010-12-02 22:17
Návrat hore  Odpovedať s citátom     

The trick is that that field will actually contain an arbitrary number of rides. For example:
<event>
<ride> ... </ride>
<ride> ... </ride>
...
</event>

I have a hunch perhaps I am being too clever. It is nice to have this data in this particular field be flexible, but it might be more trouble that it is worth...

 
mainpart     Založený: 19.01.2013   Príspevky: 1  
Príspevok Zaslal: 2013-01-19 11:22
Návrat hore  Odpovedať s citátom     

i've made success in this.
I'm handling custom serialized string via trigger on update and via php field on display
using this techique for unlimited fields creation i've created serialized field in mysql as longtext:

Kód:
$opts['fdd']['serialized']=array(
'name'=>'Run',
'options'=>'C',
'php|C'=>'return.php',
);


return.php in turn contains 4 fielded template with 3 inputs and 1 select as rude example. note that order of 1st-level items in serialized array is not preserved. there are much hardcoded in this example but this is a basic working idea.


Kód:

<?
$var=$this->cgi['prefix']['data'].$this->fds[$k];
$data=unserialize($row['qf'.$k]);$num=0;

// output serialized data
if (is_array($data)) foreach ($data as $num1=>$value){

$num++;
echo "<div class=container>\r\n";
echo "<input name='".$var."[".$num."][1]' type=text value='".$value[1]."'>\r\n";
echo "<select name='".$var."[".$num."][2]'><option value=1 " . ($value[2]==1 ? "selected" : "") .">Text1</option><option value=2 " . ($value[2]==2 ? "selected" : "") .">Text2</option><option value=3 " . ($value[2]==3 ? "selected" : "") .">Text3</option></select>\r\n";
echo "<input name='".$var."[".$num."][3]' type=text value='".$value[3]."'>\r\n";
echo "<input name='".$var."[".$num."][4]' type=text value='".$value[4]."'>\r\n";
echo "<a href=# class=\"remove\">Remove</a>\r\n";
echo "</div>\r\n";
}

//output stub used for new fields

echo "<div class=container>\r\n";
echo "<input name='".$var."[0][1]' type=text>\r\n";
echo "<select name='".$var."[0][2]'><option value=1>Text1</option><option value=2>Text2</option><option value=3>Text3</option></select>\r\n";
echo "<input name='".$var."[0][3]' type=text>\r\n";
echo "<input name='".$var."[0][4]' type=text>\r\n";
echo "<a href=#  class=".$var."_add>Add</a>\r\n";
echo "</div>\r\n"

?>
<script>
// this code used to handled multiplication of stub

$(document).ready(function(){
            //add all remove actions
            $('a.remove').click(function(){
               $(this).closest('div').remove();
               return false;            
            });

         var newRowNum = <?=$num?>;
         $('.<?=$var."_add"?>').click(function(){
            newRowNum += 1;
            var addRow = $(this).closest('div');
            var newRow = addRow.clone();
            console.log($('.container', newRow));
            $(newRow).append('<a href="" class=remove>remove</a>');
            $('.<?=$var."_add"?>',newRow).remove();
         
            $('input, select', newRow).each(function(i){
               console.log($(this));
               $(this).attr('name',$(this).attr('name').replace('[0]','['+newRowNum+']') );
            });
            addRow.before(newRow);
            $('a.remove', newRow).click(function(){
               $(this).closest('div').remove();
               return false;            
            });
            return false;
         });
      });
</script>
<?
return '';


Here is the copy on php fiddle

it's for 3 input and 1 select field.

Then we need to serialize it back when saved.

Kód:
$opts['triggers']['update']['before']='xls_importer.TUB.inc';



Kód:
<?
$name = $this->cgi['prefix']['data']."serialized";
unset($_POST[$name][0]);
$newvals['serialized']=serialize($_POST[$name]);


 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov