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.


php app/console cookbook:run  57


Receipt 2  Creating


How to create content type groups, content types and content.



a content type group

This snippet creates a content type group for a given identifier


Code Block
titlecreate content type group
        $contentTypeService = $repository->getContentTypeService();
            // instanciate a create struct
            $groupCreate = $this->contentTypeService->newContentTypeGroupCreateStruct($groupIdentifier);
            // call service method
            $contentTypeGroup =  $this->contentTypeService->createContentTypeGroup( $groupCreate );
            // print out the group
        catch( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e )
            // react on permission denied
        catch( \eZ\Publish\API\Repository\Exceptions\ForbiddenException $e )
            // react on identifier already exists

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

The solution is described in the next receipt.

Receipt 3 - 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

Code Block
        // get the user service from the repository
		$userService = $repository->getUserService();
        // load user by credentials
        $user = $userService->loadUserByCredentials($user,$password);
        // set user in repository

If the user is identified by other mechanisms the user also can be loaded by its id.