Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
   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

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


This receipt shows how to create an image content object. (Full code here)

Code Block
titlecreating an image
// get the content service from the repsitory
        $contentService = $repository->getContentService();

        // get the location service from the repsitory
        $locationService = $repository->getLocationService();

        // get the content type service from the repsitory
        $contentTypeService = $repository->getContentTypeService();

            // load the content type with identifier
            $contentType = $contentTypeService->loadContentTypeByIdentifier("image");

            // instanciate a location create struct
            $locationCreateStruct = $locationService->newLocationCreateStruct($parentLocationId);

            // instanciate a content creation struct
            $contentCreateStruct = $contentService->newContentCreateStruct($contentType, 'eng-GB');

            // set title field

            // set image file field
            $value = new \eZ\Publish\Core\FieldType\Image\Value(
                     array('path' => $file,'fileSize' => filesize($file),'fileName' => basename($file),'alternativeText' => $name ));


            // create a draft using the content and location create structs
            $draft = $contentService->createContent($contentCreateStruct,array($locationCreateStruct));

            // publish the content draft
            $content = $contentService->publishVersion($draft->versionInfo);

            // print out the content
        catch(\eZ\Publish\API\Repository\Exceptions\NotFoundException $e)
            // react on content type or location not found
        catch(\eZ\Publish\API\Repository\Exceptions\InvalidArgumentException $e)
            // react on remote id exists already
        catch(\eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException $e)
            // react on a field is not valid
        catch(\eZ\Publish\API\Repository\Exceptions\ContentValidationException $e)
            // react on a required field is missing or empty