1
votes

I'm very new to Symfony2, and struggling to rewriting everything that is currently running in an existing CodeIgniter site into a Symfony2 for a new Symfony2 version of the site.

After installing Symfony2 version 2.8.13, standard edition on a remote server, I have been able to successfully run the app.php and app_dev.php pages in my computer's Chrome browser. I used the 'create your first page' instructions to begin learning about Symfony2, and am now incrementally applying that knowledge to begin rewriting my old CodeIgniter index.php page to run in my new Symfony site.

Because the old CodeIgniter site mostly used php, css, javascript, jquery, a few plug-ins, and a some CodeIgniter functions to connect to the supporting database and render the output pages, I've decided to not rewrite the views in twig.

Instead I'm just using the Symfony controller to house the 'logic' of the CodeIgniter controller and view files. Later on I'll break the controller/view file into multiple files of one sort or another to create the reusable component files that were originally used in the CodeIgniter site, but rewritten to use the Symfony2 framework.

With all of that said, here are my questions:

1) How do I 'tell' the rendered web-page where to find the third-party plug-in files for javascript (js), images, css and other files that I put under the vendor directory? I didn't use composer to do this as most of these were files that I just copied over from my CodeIgniter site.

2) How do I 'tell' the rendered web-page where to find the non-third-party main.css file that I put under the src/project directory?

3) How do I 'tell' the rendered web-page where to find the non-third-party image files that I also put under the src/project directory?

I know that the javascript, images and css files that are not tied closely to vendor products can be placed in a few different locations, one of which is the app/Resources directory, but for the sake of clarity, especially while I'm still converting the CodeIgniter site pages, I'd rather that they be placed in page-specific directories under the src/, which at least for me is clearer and more direct than dumping them all into the Resources directory. I know of a tool to automate managing these kinds of files, Assetic, but it is no longer automatically installed in Symfony2 version 2.8.x, nor am I convinced that this will make my non-vendor files remain tied closely with their related bundles.

Another solution talked about creating a symbolic link between the Resources directory and the bundle, but I wasn't sure which direction the link was supposed to go and at what directory level it was created.

Can someone please help me understand what I need to do with respect to managing these resources without resorting to extra tools and unnecessary levels of abstraction?

Finally, since I am coming from CodeIgniter, is there a cheat-sheet of how various things were done in CodeIgniter and how those same or similar things should be done in Symfony2, with respect to the CodeIgniter function calls?

Thank you

=======================================================

Follow-Up to Thomas' response.

Thank you, Thomas.

I'm still not up on all of the Symfony terms, yet. When you say MyBundle, where do I find that directory?

/var/www/vhosts/symfony2/src/AppBundle/Controller or /var/www/vhosts/symfony2/app

Only the app directory has a Resources subdirectory or do I put it under the Controller directory in the first path?

Before I use the app/console command, I want to get this straight.

Also, since I'm not using twig, can I still use the {% %} notation to specify where the html link and img tags get there files? As I said originally, I don't want to convert my html statements into twig at this time, the html is already finished and the resulting pages are exactly what I want.

Thanks again.

P.S., I tried to respond in a comment, but that doesn't work very well because it takes all of the line-feeds and extra spaces out. A know there must be a way to add to this thread without editing the original posted question, but I don't see anything other than answering my own question, which I definitely can't do. So would someone be so kind and please tell me how to add my own responses to this thread?

1

1 Answers

1
votes

A good way is using symlinks

First you should never put files directly into vendor directory as it can be deleted, if you do a composer install/update, and it's not a good practice at all.

Create a public folder in the Resources folder of your bundle using these resources, or in the Resources folder of the app folder.

MyBundle/Resources/public

Then put your resources inside this folder, example i put js/jquery.min.js

Then run a cmd and use the following command line

app/console assets:install

with option --symlink

And that will install all your assets into web folder.

To access your assets use {{ asset('myfolder/js/jquery.min.js' }} in a Twig view for example. Hope this helps.

You can also take a look at the official documentation on using Assetic to manage your assets.

http://symfony.com/doc/current/assetic/asset_management.html

http://symfony.com/doc/current/best_practices/web-assets.html


EDIT :

I'm still not up on all of the Symfony terms, yet. When you say MyBundle, where do I find that directory?

When i refer to MyBundle folder i assume you've created a bundle in your app, you should maybe take a look at this page (http://symfony.com/doc/current/quick_tour/the_architecture.html) which explains the basic architecture of a symfony application. To generate a new bundle with his basic structure you can follow this page (http://symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/generate_bundle.html).

Only the app directory has a Resources subdirectory or do I put it under the Controller directory in the first path?

When you create a new bundle for your application with the steps described in the link i gave you you'll have a Resources directory in your bundle folder. (if you don't need to create a new bundle in your app you can use the AppBundle directory which symfony create automatically)

Also, since I'm not using twig, can I still use the {% %} notation to specify where the html link and img tags get there files? As I said originally, I don't want to convert my html statements into twig at this time, the html is already finished and the resulting pages are exactly what I want.

Symfony comes with twig as it's templating engine but if you don't want to use it you can. I think this link may help you with that (http://symfony.com/doc/current/templating/PHP.html) you should know that {% %} is a twig syntaxe so i think you won't be able to use it if you're not using twig.

Hope this helps.