The Symfony bundle is a group of files and directories that are organized into a specific structure.
To create a bundle in Symfony follow below steps:
Step1 : Choose a namespace. The namespace must contain the name of the vendor and bundle name. Something like Courseya\DemoBundle.
Step2 : Create an empty class named CourseyaDemoBundle and extend it to Bundle class.
Example :
namespace FreeTimeLearn\DemoBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class FreeTimeLearnDemoBundle extends Bundle {
}
Step3 : Save the above class in src/Courseya/DemoBundle directory.
Step4 : Register the above class in the bundle list supported by the application in the AppKernel class.
Example :
public function registerBundles() {
$bundles = array(
// ...
// register your bundle
new FreeTimeLearn\DemoBundle\FreeTimeLearnDemoBundle(),
);
return $bundles;
}
Step5 : Use generate:bundle command to generate your bundle.
php bin/console generate:bundle --namespace = FreeTimeLearn/DemoBundle
That's all you have created your first bundle in Symfony.