ScoRpion
ScoRpion

Reputation: 11474

Separating Common Code In Symfony2 Within my Bundles?

I have created Bundles and they share some Common code. (File Upload Class, Gmailer Class) Now I want to create a separate file within my Bundles or Anywhere, where i can put this common code and then I want to create objects of its classes inside all my bundles.

Here is my folder structure

-src
  -College
     -StudentBundle
        -Controller
        -Entity
        -OtherApplication
           -All3rdPartyClasseshere.php
     -UserBundle
     -TeacherBundle

Now when I tried to auto load it like this

autoload.php

$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_'            => __DIR__.'/../vendor/twig/lib',
'Uploader_'        => __DIR__.'/../../src/College/StudentBundle/OtherApplications',

But when i try to create an object in my controller it gives an error. I didnt use or include anything inside my controller. How could i create objects of the classes that i separated in another file.

Upvotes: 1

Views: 503

Answers (1)

Daniel Ribeiro
Daniel Ribeiro

Reputation: 10234

First of all, third-part libraries, even if they are specifically related to your bundle, should not be inside the bundle structure.

The recommended way to handle your non-bundle common code is to treat it as external libraries, and manage them with composer.json.

About the Bundle structure, maybe this question can help you get in the right path.

Upvotes: 1

Related Questions