Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 8 Next »

The following recipes show how to create simple content. As we don't want to rely on a specific installation with predefined content types we first show how to create a content type group and a simple content type within this group. Then we will create a content object of the newly created content type. The last two recipes show how to create content containing images and xml text.

Creating a content type group

This snippet creates a content type group for a given identifier (Full code here).

create content type group

 

If this snipped is run with the same init code from recipe 1 we will get an UnauthorizedException.

The solution is described in the next recipe.

Setting the user for authorizing actions

By default the repository assumes the anonymous user is acting. To change this, the following code can be executed

authentication

If the user is identified by other mechanisms the user also can be loaded by its id via the service method

$userService->loadUser($id)


Creating a content type

With this snipped a content type with two fields of type 'ezstring' is created. (Full code here).

create content type

 

Creating content

In this recipe content is created under a given parent location. It is assumed that the loaded content type is the one created in recipe 4. (Full code here).

create content

 

Updating Content

In this recipe the previously created content is updated with a new title and body in the same language. (Full code here)

update content

Translating content

It is the same code as for updating (see recipe 6). The initial language should be set to the translation language.

translating

Multiple translations at once

It is possible to make an update in content  or create content with more than one language. But there is a restriction - only one language can be assigned to the newly created version (which is displayed in the 4.x admin GUI, in the translations column).

update multiple languages

Creating Content containing an image

This recipe shows how to create a content object containing an image. (Full code here)

creating an image

 

Create Content with XML Text

This recipe shows how to create content with xml text. As a content type, the folder is used where the description is filled with xml. It is also shown how to embed the previously created image in the description. The image Id is given by a command line argument.

working with xml text
  • No labels