How to create/use custom classes and helper in symfony 1.4?

med picture med · Mar 6, 2011 · Viewed 9k times · Source

What is the best way to put custom library or helper methods in symfony? I am using doctrine with my project. One place I consider to put is under

project_root/lib/vendor/MyClasses/
But if I want to create a class or helper function which will use some core symfony/doctrine methods and return a result then how to do that and where should I put it? I want it to call from different modules to avoid code duplication.

Answer

Burgi picture Burgi · Mar 7, 2011

As for the custom library part of the question, you might probably want to put your external library into the lib/vendor folder. Since symfony doesn't automatically load everything that's in there, you'll have to tell its autoloader to do so.

You can either extend your config/ProjectConfiguration.class.php (as described here) or (and this is the much simpler and cleaner way) you add them to your config/autoload.yml (you might have to create this one). For the latter option, this is a great place to start looking at.