0

I want to include normal php script that I have made before for another project in DefaultController.

public function indexAction()
{       
            include('./GenFunctions.php');

then I put GenFunctinos.php in the same directory as DefaultController, but it shows 'failed to open stream'

How can I include this script?

I understood this is the illegular way to include in the perspective of symfony2.

But I want to do this to reuse the script. please help me.

3
  • Use the file's absolute path: __DIR__ . '/GenFunctions.php' or /path/to/GenFunctions.php Commented Jun 25, 2013 at 18:45
  • 2
    is it a class or just some functions ? maybe you should refactor it to a class using namespaces and integrate it with composer ... Commented Jun 25, 2013 at 18:46
  • 1
    100% with @nifr. Composer is the way to go when adding libs to a symfony2 project. Commented Jun 25, 2013 at 19:02

1 Answer 1

4

You can autoload this file with composer.

http://getcomposer.org/doc/04-schema.md#files

{
    "autoload": {
        "files": ["src/GenFunctions.php"]
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.