Forums / Developer / how to instanciat a eZDataType classe ?

how to instanciat a eZDataType classe ?

Author Message

Peretjatko Alexandre

Tuesday 24 June 2008 7:56:57 am

Hi,

I d'ont understand how to use the eZDataType classe.
In the documentation, I've found :

eZDataType::eZDataType(  	$dataTypeString,
		$name,
		$properties = array()	 
	) 	
Initializes the datatype with the string id $dataTypeString and the name $name.

So I've write :

	
include_once('kernel/classes/ezdatatype.php');
$l_OBJ_File =& eZDataType::eZDataType("dataType", "name");

and I got the message :
Fatal error: Call to undefined method: stdClass->isindexable() in C:\eZpublish\ezpublish\kernel\classes\ezdatatype.php on line 88

I use an ezpublish 3.10. Is it a bugging version for this classe ? What's wrong in my code ?

Thanks for your help.

Regards

Alex.
--------------------------------------------------------------
Personnal website : http://www.alex-design.fr

Vidar Langseid

Thursday 03 July 2008 2:33:10 am

eZDataType is meant as base class for other datatypes.

I am not sure what you want to do, but trying to instantiate a datatype doesn't make much sense. The content needs to be stored in a attribute in a contentobject. Once you have the content object, the different datatypes will be instantiated for you

Best regards,
Vidar

Peretjatko Alexandre

Thursday 03 July 2008 2:55:16 am

Thanks for your answer.

Well.... My first problem was to read a file content from an uploaded file and during all my investigations, I've found the classe eZDataType which seems to be ok to do the job for me.

But reading your answer I should be on a wrong way.

Regards

Alex.
--------------------------------------------------------------
Personnal website : http://www.alex-design.fr

Hans Melis

Thursday 03 July 2008 2:29:36 pm

It depends on where you're handling uploaded files, but if you're in your own module I suggest you take a look at the eZHTTPFile class. You can find it in the lib/ezutils/classes dir.

If that's not what you're trying to do, please explain your problem in greater detail :-)

Hans
http://blog.hansmelis.be

Peretjatko Alexandre

Friday 04 July 2008 1:18:22 am

Thanks Hans Melis,

Your right, my problem is not well explain.
- The user, upload a file in the Back Office in a file object. For that, I've create a file object in the BO, in a specific folder. The user will use always the same object, so I'll have different version. This is a text file.
- With a cron job I have to import in a specific database datas stored in the file. For that, I have to read my file content with a php script, and my trouble is to point that file.

But I don't know how to read my text file content. So I search in eZDataType classe without success. And I'm not sure that the eZHTTPFile class is the good one.

Regards

Alex.
--------------------------------------------------------------
Personnal website : http://www.alex-design.fr

Hans Melis

Friday 04 July 2008 4:17:20 am

eZHTTPFile is indeed not what you need in your case. You are actually trying to access a file that is a part of a content object.

So first of all, you need to fetch the object in some way. Once you have it, you'll have an instance of the eZContentObject class. Objects of that class have a method called <i>dataMap</i>. That method returns an array with the following structure:
- key: identifier of the attribute as specified in the content class
- value: instance of eZContentObjectAttribute

The class eZContentObjectAttribute actually (for the real data at least) wraps around the datatype. If you query the eZContentObjectAttribute instance for content(), you will get the content that has been stored by the corresponding datatype. That content can be a scalar value, an array or even an object of class. The latter is the case for attributes of the type file.

The datatype for files is called ezbinaryfile (kernel/classes/datatypes) and the content of that datatype returns an instance of the class eZBinaryFile.

That should get you on the road. I obviously left some things out, but the goal is that you actually learn something. So it's your task to connect the dots ;-)

hth

Hans
http://blog.hansmelis.be