This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal

eZ Community » Forums » eZ Publish 5 Platform » Creating class and attributes with PHP

Creating class and attributes with PHP

Creating class and attributes with PHP

Thursday 09 April 2015 1:35:36 pm - 9 replies

Hi there,

I have followed this tip :

And there is the following error :
Call to a member function initializeClassAttribute() on a non-object ezpublish

I guess it's because the following line return null.

The datatype i'm trying to use is "ezstring" for the first attribute.

The class is created correctly but not the attributes. Can anyone help ?
Plus, the variable : $GLOBALS["eZDataTypes"] is not initialized as well. (NULL)


Ez Version : 2014.11

Modified on Thursday 09 April 2015 1:37:53 pm by Task Mikaël

Thursday 09 April 2015 3:48:49 pm

Hi Mikaël,

how are you running that code? It looks like environment has not been initialized.

Also, have you considered using new API for this? You can use integration tests as an example to get you kickstarted. Also check out command examples in CookbookBundle.



Thursday 09 April 2015 3:52:46 pm

I second Petar. Create a new content type is MUCH easier with new api. Also creating content and some other task. 

Thursday 09 April 2015 4:01:08 pm


thanks for answers, the code is running on a Command launched via :
php ezpublish/console create:test

I didn't try to use the new API I'll check your links.


Modified on Thursday 09 April 2015 4:02:22 pm by Task Mikaël

Thursday 09 April 2015 5:12:01 pm

Hi again,

It is true that the new API is working perfectly !

Only one problem remains :
- How do I change the target database ?

I am working on an import script that uses :
- 1 command to get all data (api 4 with eZDB) from one DB
- 1 command to create target structure (contentType, contentobject ect..) to another DB

The script used the old database to create my contentType. I would like to be able to switch repository at ease.

Another question : is it possible to use the eZ 5 API to get data from an eZ 4 database ?
Because it's seems that the new API is MUCH easier happy.gif Emoticon

Info about db :
First DB : eZ 4 => upgraded to 5.4 following those tutorials :

Second DB : Fresh eZ 5 install


Modified on Thursday 09 April 2015 5:13:30 pm by Task Mikaël

Thursday 09 April 2015 5:28:32 pm

As long as the database has been upgraded as you describe it should work to read it using API.

However if you have many custom datatypes this might not work that well as you would need to implement them first on Platform/new Stack.  

A bit unsure how to have one instance with one db and one with the other, but Platform stack is all dependency injection, so should be possible somehow. probably just a matter of separate symfony environments and loading both as separate instances.

Modified on Thursday 09 April 2015 5:30:44 pm by André R

Thursday 09 April 2015 5:32:27 pm


the database is still the same for new and Legacy stack, so it should be the same if upgraded to the same version 5. So yes, that should be entirely possible.

The way to do it would be configuring the database for a siteaccesses, and then running the script with --siteaccess parameter, similar as was done with Legacy stack scripts. But, you can't just switch the database in PHP, it was not made to work that way, as the whole environment needs to be set-up in advance.



Thursday 09 April 2015 5:38:13 pm

Ok thanks !
i was wondering because there is a field in my new eZ 5 DB that is not on the upgraded eZ 4 DB(ezcontentclass->always_available for example)


I'll try this.


I'm marking this topic as solved.

Modified on Thursday 09 April 2015 5:45:49 pm by Task Mikaël

Thursday 09 April 2015 6:34:40 pm

Hello Task,

I am late to the party! But I wanted to clearly mention that I thought you were trying to run legacy code in a non-legacy context which is why I think it was not working correctly.

That said I'm pleased that your using the better new stack api instead now moving forward to better solve your problems and provide for your needs.

Best wishes!


Friday 10 April 2015 10:02:25 am

Hi heath,

No worries, thanks for answering ! I hope you are doing fine.

I have found the solution, i was connecting to the upgraded database in the config file, i will change the config to connect to the new one.
The eZ 4 API allows us to have several instance, so i'm just going to use the eZ 4 API to get data, and let the rest do the work.




You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from