symfony routing not take into account in app/config/routing - symfony

Here my main routing file (in app/confige/routing.yml), and the point is that whatever route I put, it works! I'm a bit lost!
sdz_administration:
resource: "#sdzAdministrationBundle/Resources/config/routing.yml"
prefix: /{_locale}//whatever
sdz_bikind:
resource: "#sdzBikindBundle/Resources/config/routing.yml"
prefix: /{_locale}//whatever
requirements:
_locale: en|fr|es
sdz_user:
resource: "#sdzUserBundle/Resources/config/routing.yml"
prefix: /
I have erased the cache and delete the browsing history. But it did nothing.

Related

FOSRestBundle 2.4 | How to load rest type route

I upgraded my FOSUserBundle to 2.4 from 2.1 while I was upgrading my project to Symfony 3.4 from 2.8.
With the same code that worked before, and this yml file:
# app/config/routing.yml
api_request_backend:
type: rest
prefix: /api
resource: "#AppBundle/Resources/config/default.yml"
-
# AppBundle/Resources/config/default.yml
api:
type: rest # This resource will have RESTful routes
prefix:
resource: "#AppBundle\Controller\ApiController"
name_prefix: api_
apiV2:
type: rest # This resource will have RESTful routes
prefix: /v2
resource: "#AppBundle\Controller\ApiV2Controller"
name_prefix: api_v2_
api_user:
type: rest # This resource will have RESTful routes
prefix:
resource: "#AppBundle\Controller\ApiUserController"
name_prefix: api_
I receive this error:
Exception thrown when handling an exception
(Symfony\Component\Config\Exception\FileLoaderLoadException: The file
"/var/www/project/src/AppBundle/Resources/config/default.yml" does
not contain valid YAML in
/var/www/project/src/AppBundle/Resources/config/default.yml (which
is being imported from "/var/www/project/app/config/routing.yml").
Make sure there is a loader supporting the "rest" type.)
Where am I wrong? I also tried to downgrade FOSRestBundle to 2.3.1 (I read this here) but nothing changes.
For newest (>3.0) you must change the route type from rest to annotation.
The issue is the invalid YAML. The following works:
# app/config/routing.yml
api_request_backend:
type: rest
prefix: /api
resource: '#AppBundle/Resources/config/default.yml'
and
# AppBundle/Resources/config/default.yml
api:
type: rest # This resource will have RESTful routes
resource: '#AppBundle\Controller\ApiController'
name_prefix: api_
thanks to xabbuh for the fix

How do I ignore the top level domain when using host to route to a subdomain in Symfony?

I have a website that I'm testing locally using domain.lc. The website has a subdomain sub.domain.lc that routes to a different controller, like this:
my_bundle:
host: sub.domain.lc
resource: "#MyBundle/Controller/"
type: annotation
prefix: /
The subdomain routes to my bundle because of the host, but I would like it to also route to this bundle using sub.domain.com. Is there a way to ignore the top level domain using the host?
You can use placeholder like this:
my_bundle:
resource: "#MyBundle/Controller/"
type: annotation
prefix: /
host: "{domain}"
defaults:
domain: "%domain%"
requirements:
domain: "sub\.domain\.(lc|com)"
But there is a problem with generating absolute URLs. It depends on where your app is currently running (loc or com) and you need to specify it as container parameter (parameters.yml is good place). Link to similar problem.
Although kba did provide an answer that helped me very much and I will in fact accept his answer as the right one, I want to show you what my route ended up looking like:
my_bundle:
host: sub.domain.{tld}
resource: "#MyBundle/Controller/"
type: annotation
prefix: /
requirements:
tld: lc|nl
defaults:
tld: nl
I didn't use the Service Container Parameter in my route, because I know my domain won't change. Only my top level domain can change.

Symfony2 - Managing routes involving 2 kinds of bundle

I am a beginner in Symfony2, and I am working on Symfony2 project in which a kind of general bundle, let say CoreBundle, is managing all the routes (in this form, first.domain/a-route, second.domain/a-route, third.domain/a-route,...) of the website. Now I have been creating FirstBundle, SecondBundle, ThirdBundle with the idea to "transfer" the management of routes of each subdomain (firt, second, third,...) to the related bundle.
Beginning with the transfer of routes from CoreBundle to FirstBundle by editing /app/config/routing.yml file from:
resource: "#ProjectFirstBundle/Resources/config/routing.yml"
prefix: /
host: "{subdomain}.{domain}"
defaults: { _controller: ProjectFirstBundle:Public:aroute }
domain: %project_domain%
requirements:
domain: "%project_domain%"
subdomain: 'first'
to:
resource: "#ProjectFirstBundle/Resources/config/routing.yml"
prefix: /
And then creating FirstBundle/Resources/config/routing.yml file with the following content:
project_first_aroute:
path: /a-route
host: "{subdomain}.{domain}"
defaults: { _controller: ProjectFirstBundle:Public:aroute }
domain: %project_domain%
requirements:
domain: "%project_domain%"
subdomain: 'first'
And of course I have created controller and view files using the same schema as CoreBundle (by making an adaptation -- inheritance for .twig files). As the result, the following exception is being returned when running first.domain/a-route:
Fatal error: Uncaught exception 'Symfony\Component\Yaml\Exception\ParseException' with message 'Unable to parse at line 15 (near " domain: %project_domain%").' in
Any suggestions as to how I can effectively achieve my goal?
Thanks in advance for your help.
I Came to find out that I should have created FirstBundle/Resources/config/routing.yml file as followed:
project_first_aroute:
path: /a-route
host: "{subdomain}.{domain}"
defaults: { _controller: ProjectFirstBundle:Public:aroute, domain: "%project_domain%" }
requirements:
domain: "%project_domain%"
subdomain: 'first'
The error message is a syntax error from the Yaml Parser.
Please note that correct idention is essential in a Yaml File and check if you need to wrap %project_domain in quotes on the first occurence (see stackoverflow syntax highlighting, it looks odd).
-
Debugging routes in Symfony2
app/console router:debug

Symfony Routing with variable host

I am using the current version of Symfony and want to define a route with a specific subdomain. This is what I have:
xyz:
resource: "#XYZ/Controller/"
type: annotation
prefix: /
host: "xyz.symfony.dev"
I want to have symfony.dev variable, only xyz as a subdomain is a static value. How can I realize this? I don't get it in the documentation.
I'm not good with regex but this answer your question:
xyz:
resource: "#XYZ/Controller/"
type: annotation
prefix: /
host: "xyz.{domain}.{ltd}"
requirements:
domain: "([a-z0-9-])+"
ltd: "([a-z])+"
EDIT: Regex added

Routing with annotation not working in prod Syfmony2

I am using annotations to generate my routes with Symfony2.3.
My routes work perfectly fine in dev environment, but the server gives me 404 when I try to access them in prod.
I have warmed up and cleared my cache several times to no result. I am totally lost. I don't understand why everything works fine in dev, but not in prod.
Anyone has an idea ?
Edit :
This is app/config/routing.yml
hakim_admin:
resource: "#HakimAdminBundle/Controller"
type: annotation
prefix: /
hakim_resume:
resource: "#HakimResumeBundle/Controller"
type: annotation
prefix: /
And this is app/config/routing_dev.yml
_wdt:
resource: "#WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_configurator:
resource: "#SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /_configurator
_main:
resource: routing.yml
JMSTranslationBundle_ui:
resource: #JMSTranslationBundle/Controller/
type: annotation
prefix: /_trans
Thanks
check if you have set up to use apache rewrites in your config_prod.yml like this
parameters:
router.options.matcher.cache_class: ~ # disable router cache
router.options.matcher_class: Symfony\Component\Routing\Matcher\ApacheUrlMatcher
if so, then you might need to regenerate your routes.

Resources