Access external directories from symfony2 - php

I have images that are stored in a directory in /var/lib/myproject. So they are outside of my symfony project. I would like to display them in a twig template or via css.
How could I access them as symfony is catching every url and rewrites them?
Setting a specific route doesn't work :
my_project_res:
resource: "/var/lib/myproject"
prefix: /res

Related

Setting up multiple Kernels in Symfony 4

I am trying to set up a multi-site architecture in Symfony 4 using multiple Kernels.
It would be too lengthy to post all of the changes I have made but I basically followed the Symfony docs for creating a new Kernel and the changes I made can be viewed in the following pull request.
When I attempt to run the api kernel locally (php bin/api server:run) I get the following error message:
I am simply trying to load the home controller and template using the new Kernel
# config/api/routes.yaml
home:
path: /
controller: App\Controller\Home::index
Place routes.yaml under config/routes directory, otherwise Symfony treats this file as a framework configuration file.
Or you can reconfigure kernel to load routes files from api directory by editig configureContainer and configureRoutes methods of ApiKernel.

What Does the `type:` Configuration in a Symfony Route Configuration Control?

What does the type: configuration in a Symfony routing file control? What are its valid values?
I can't find this configuration field explicitly documented anywhere. It's referenced indirectly in Symfony's routing documentation.
app_directory:
resource: '../legacy/routing/'
type: directory
and seems related to loading in additional routes. However, its behavior (or all its allowed values) doesn't seem to be explicatly defined anywhere. I can make a guess that it somehow tells Symfony how to load the external routes, but I'd love to know
Is my guess correct?
Are there valid values other than directory or annotation?
Is this formally documented anywhere?
Is there a spot in the Symfony internals that would be a good place to start finding these answers for myself?
You can find how the type works in the Symfony documentation, see code below. It controls if the routes should be loaded from the PHP annotations or the YAML or XML files found in that (bundle) directory.
app_file:
# loads routes from the given routing file stored in some bundle
resource: '#AcmeOtherBundle/Resources/config/routing.yaml'
app_annotations:
# loads routes from the PHP annotations of the controllers found in that directory
resource: '../src/Controller/'
type: annotation
app_directory:
# loads routes from the YAML or XML files found in that directory
resource: '../legacy/routing/'
type: directory
app_bundle:
# loads routes from the YAML or XML files found in some bundle directory
resource: '#AppBundle/Resources/config/routing/public/'
type: directory

Symfony Bundle Load YML Configuration

Since I am new to Symfony and I couldn't manage to find some useful information in google I decided to write to you.
I've read about the way of loading custom DI alias information from a dependency injector in your bundle and how to create a Configuration class that will expose the alias structure. However I am to some extend confused how I can create a file, for example routing.yml, in my AcmeBundle/Resources/config/ folder and read the data from it. E.g:
some_alias:
resource: "#AcmeBundle/Controller/"
type: annotation
prefix: /
I want to make a bundle with routing, independent from the main configuration files in the app folder.
You can create your bundle routing.yml in your WhateverBundle/Resources/config/routing.yml and the in the app/routing.yml just include your bundle's routes.
mybundleorwhatever:
resource: "#WhateverBundle/Resources/config/routing.xml"

Symfony 2 : Web debug tool bar not showing (404 error) and Twig path function's not working

I have built a symfony 2.6 web site and I deploy it in an url like this :
https://www.example.com/abc/
This url points on the "web" directory (as the root directory).
The web site is working fine, but there is two issues :
1) Web debug tool bar is not showing because the widget is pointing on https://www.example.com/ not on
https://www.example.com/abc/ and I don't understand why ?!
2) Same thing for Twig path() function, it is also pointing on https://www.example.com/ not https://www.example.com/abc/
So do you have any idea about that ?
I Finally Got it, "abc" is not a physical folder it's just a "virtual" path defined in the virtual host of www.example.com,
so while https://www.example.com/abc/ is pointing on web folder of my symfony project, which is the root repository by default in Symfony framework, the folder "abc" doesn't exist in reality,
In fact I use to modify in this script "/public_html/vendor/symfony/symfony/src/Symfony/Component/Routing/Generator/UrlGenerator.php" this way by enforcing the "/abc" part in the dynamically
generated url :
$url = $schemeAuthority."/abc".$this->context->getBaseUrl().$url;
I think Symfony doesn't take this case into account by default.
Other thing that can cause this issue too is to verify the scheme (http or https) of your website in the routing configuration (routing.yml) of your project, example :
test:
resource: "#testBundle/Controller/"
type: annotation
prefix: /
schemes: [http]

Symfony2 FOS Rest bundle routing FileLoaderLoadException controller

I have a very strange issue, with my Symfony2 setup.
I'm working on a restful webservice and would like to setup routing.
I have a fully working application and woud like to change my routing.yml config.
Working configuration
my_product:
resource: My\Bundle\ProductBundle\Controller\DefaultController
type: rest
prefix: /
When I change that to:
my_product:
resource: "#MyProductBundle/Controller/"
type: rest
prefix: /
I get the following error:
Symfony\Component\Config\Exception\FileLoaderLoadException"
message="Can't find class for controller
"#MyProductBundle/Controller/" in #MyProductBundle/Controller/ (which
is being imported from
"/home/myproduct/domains/example/v5/app/config/routing.yml"). Make
sure the "MyProductBundle" bundle is correctly registered and loaded
in the application kernel class. If the bundle is registered, make
sure the bundle path "#MyProductBundle/Controller/" is not empty.
When I change the type from "rest" to "annotation", the error disappears.
What am I doing wrong? I can't find it out and my searches lead to nothing.
Many thanks in advance!
You can't currently import all of a bundle's controllers at once when using FOSRestBundle. It will be added in FOSRestBundle 2.0. Import your controllers individually like in your first example.

Categories