Then use the app/console application, with the
generate:bundle command, to start the bundle generation wizard.
$ php ezpublish/console generate:bundle
Your application code must be written in bundles. This command helps you generate them easily. Each bundle is hosted under a namespace (like Acme/Bundle/BlogBundle). The namespace should begin with a "vendor" name like your company name, your project name, or your client name, followed by one or more optional category sub-namespaces, and it should end with the bundle name itself (which must have Bundle as a suffix). See http://symfony.com/doc/current/cookbook/bundles/best_practices.html#index-1 for more details on bundle naming conventions. Use / instead of \ for the namespace delimiter to avoid any problem. Bundle namespace: EzSystems/CookbookBundle
This is the skeleton for a command line script.
One class , with a name ending with "Command" (
HelloCommand), that extends
Symfony\Bundle\FrameworkBundle\Command\Command, and is part of our bundle's Command namespace. It has two methods:
execute(). We also import several classes & interfaces with the use keyword. The first two,
OutputInterface are used to 'typehint' the objects that will allow us to provide input & output management in our script.
In this short chapter, we will see how to create a new route that will catch a custom URL , and execute a controller action. We want to create a new route, /cookbook/test, that displays a simple 'Hello world' message. This tutorial is a simplified version of the official one that can be found on http://symfony.com/doc/current/book/controller.html.
We define a route that matches the URI /cookbook/* , and executes the action hello in the Default controller of our bundle. The next step is to create this method in the controller.
Controller actions must return a Response object that will contain the response's content, the headers, and various optional properties that affect the action's behaviourbehavior. In our case, we simply set the content, using
setContent(), to "Hello $name". Simple. Go to http://ezpublish5/cookbook/hello/YourName, and you should get "Hello YourName".