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

Versions Compared

Key

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

...

Go to the eZ publish installation

cd <ezpublish installation root>

Generate a new Bundle

php app/console generate:bundle

Now follow the instructions. This will create a bundle eZ/Publish/Bundle/CookBookBundle in the src directory of the installation root.

...

Add a Command directory to the bundle

cd <ezpublish installation root>/eZ/Publish/Bundle/CookbookBundle

mkdir Command

add the following class file CookbookCommand.php in the directory Command

 

Code Block
languagephp
titlemy first command
<?php
/**
 * File containing the CookbookCommandCookBookCommand class.
 *
 * @copyright Copyright (C) 2012 eZ Systems AS. All rights reserved.
 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 * @version //autogentag//
 */
namespace eZ\Publish\BundleBundles\CookbookBundleCookBookBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class CookbookCommandCookBookCommand extends ContainerAwareCommand
{
    protected/**
function configure()    * {
		// define a new app console command 'cookbook:run' which takes one argument mapped to contentId
		 $this->setName( 'cookbook:run' )
    This method override configures on input argument for the content id
     */
    protected function configure()
    {
     ->setDefinition(   $this->setName( 'cookbook:run' )->setDefinition(
              array(
                       new InputArgument( 'contentId', InputArgument::REQUIRED, 'An existing content id' )
            )
        );
    }

    /**
     );* execute the command
}     * @param InputInterface $input
     * @param OutputInterface $output
     */
    protected function execute( InputInterface $input, OutputInterface $output )
    {
	        // fetch the commandinput line argument
	    $contentId     $contentId = $input->getArgument( 'contentId' );

         // get the repository from DIthe di container
        $repository = $this->getContainer()->get( 'ezpublish.api.repository' );

                /*********** receipt code starts here ********************************/ 
        // get the content service from the repositoryrepsitory
        $contentService = $repository->getContentService();

        try
        {
             // callprint loadContentInfoout andthe printcontent outinfo for the gicen content id
        print     print_r( $contentService->loadContentInfo( $contentId ) );
        }
        catch( \eZ\Publish\API\Repository\Exceptions\NotFoundException $e )
        {
            // if the id is not found
            $output->writeln( "No content with id $contentId" );
        }
     /*********** receipt code ends here ********************************/
     }
}

catch( \eZ\Publish\API\Repository\Exceptions\UnauthorizedException $e )
        {
            // not allowed to read this content
            $output->writeln( "Anonymous users are not allowed to read content with id $contentId" );
        }
    }
}





 

run f.e.

php app/console cookbook:run  57

 

Receipt 2  Creating Content

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