1

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
ScoRpion
  • 11,364
  • 24
  • 66
  • 89
  • @FractalizeR :- Class not found in /opt/lampp/htdocs/college/src/College/StudentBundle/Controller/StudentController.php – ScoRpion Apr 11 '12 at 13:39

1 Answers1

1

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.

Community
  • 1
  • 1
Daniel Ribeiro
  • 10,156
  • 12
  • 47
  • 79