1

I have a non-Symfony project that I'd like to include in a Symfony project.

The project has lots of relative paths in forms like

<form action="actions/check.php"> 
    <input type="text" name="pages">
    <input type="submit" value="Check">
</form>

or including files like include '../include/class.php';

Completely changing it to work in Symfony would be very troublesome, so is there any way to make these relative paths work in a Symfony project?

I've included the project in a folder inside a bundle, but obviously submitting a form sends me to a relative page that doesn't exist on the website because a route wasn't defined for that page. For instance, for the above form, I am sent at mywebsite/actions/check.php.

Creating routes for those wouldn't do much, as I need to create Symfony controllers for them, and that means I'll need to redo the project, and copy/paste code from the original files in those controllers.

Is it possible to use non-Symfony code with relative paths in a Symfony project? I'm thinking the relative include paths would work, but what about the form actions?

7
  • I don't think that 'd be a good idea, and I doubt that it'll work. Decouple your old project in separated classes and views, and use namespacing Commented Sep 28, 2015 at 20:43
  • Namespacing could work, but what about the forms? I'll need to write controllers to handle each of them? Copy and paste code from my project's files? Commented Sep 28, 2015 at 20:45
  • Split them in twig views and use symfony forms, check the docs symfony.com/doc/current/book/forms.html Commented Sep 28, 2015 at 20:46
  • I think this answer might help you: stackoverflow.com/questions/14255777/… It talks about static files, which you are trying to serve your .php's as of. I mean, does your file exist in /actions/check.php? Commented Sep 28, 2015 at 20:49
  • @SparK yes, exactly what I needed. Kind of strange to include it in web/docs, but if it does the job then I guess I shouldn't complain. I know how to make forms and how I'd redo it as a Symfony project, just don't want to do it. And was also pretty curious how it could work otherwise. Found out something new in the process, so all is great. Commented Sep 28, 2015 at 20:57

1 Answer 1

1

You are trying to serve the script as a static file, bypassing the router. Usually there are static routes the framework uses to serve CSS, JS, JPG, PNG, etc... Your static .PHP files should be into that folder.

This answer: Rendering static content in Symfony2 project talks about how to bypass the symfony router with a .htaccess file, which I presume you already have a conditional (RewriteCond) in it:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>

What it tells us is: if the file exists in the folder structure, it will not use the router and will serve it as is.

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.