Forums / Developer / New datatype with 2 or more attribute (data_text)

New datatype with 2 or more attribute (data_text)

Author Message

Andrea Palladino

Tuesday 03 February 2004 12:32:43 am

Hi,
we need a new datatype that can store 2 or more data (varchar).
I see that in the ezcontentobject_attribute table there is only 1 data_text field. We'll need to store 2 (or more) data_text on the same datatype.

Any suggestion?

Thanks,

Andrea

Wenyue Yu

Tuesday 03 February 2004 1:31:15 am

Hi,

Perhaps you can use xml to save those attributes, look how datatype ezselection implements.

Regards,
wenyue

Jim Reverend

Friday 06 February 2004 7:52:07 am

I think that, in most cases, you'll have to do something special to make this happen. There are many ways to do this, but I'll give you an example of one.

Let's say, for instance, that you wanted a "Car" datatype. This data type would have 3 attributes, Year, Make, and Model. There are two ways, I can see, to do this. Either way, you'll need to create a new datatype in PHP, so get your programming skills ready.

The first way, is to create a table in the database. In "data_int" you'll store the ID of the record in the database that holds the information you've stored. Your datatype object, in this case, will be responsible for pulling that data out and putting it back in. I believe ezURL does it this way.

A second, easier method, would be to use PHP's serialize function. Build an array of your items like so....

$blah = array('year' => '2003', 'make' => "Saturn", 'model' => 'ION3');

The serialize it.. .like so

$ser = serialize($blah);

Then store the value of $ser in data_text.

I'm not sure how the internals of DataTypes work just yet, as I haven't gotten to that part of the learning process yet. But, when I do, I can post an actual PHP code example of this datatype.