this is my forder structure project structure image
this is my routing config
this is my routing config
app:
resource: "#AppBundle/Controller/"
type: annotation
admin:
resource: "#AdminBundle/Controller/"
type: annotation
prefix: admin/
defaults: { _controller: AdminBundle:Default:index }
Hi guys!
This is my project
but I go to link http://127.0.0.1:8000/admin
I get message
No route found for "GET /admin"
Please help me
Sorry my english is not very well
Thanks Guy
Try like this:
admin:
resource: "#AdminBundle/Controller/"
type: annotation
prefix: /admin
defaults: { _controller: AdminBundle:Default:index }
(slash before admin and typo on AdminBunlde)
Related
I'm trying to create prefix for only one domain in Symfony 4.
I would like to have following domains:
domain1.com
domain1.pl
domain2.com
**domain2.com/pl**
First option, I have tried
In /config/routes/annotations.yaml:
controllers:
resource: ../../src/Controller/
type: annotation
controllers_localized:
resource: ../../src/Controller/
type: annotation
prefix:
pl: /pl
en: /
But it adds to all domains prefixes and I want prefix only for domain2.com > domain2.com/pl
Second option, I have tried
In /config/routes.yaml route to the same controller:
index:
path: /
controller: App\Controller\DefaultController::index
index_localized:
path: /{_locale}
controller: App\Controller\DefaultController::index
defaults:
path: /pl
permanent: true
careers_localized:
path:
en: /careers
pl: /{_locale}/kariera
defaults:
path: /pl
permanent: true
controller: App\Controller\CareersController::careers
It works, but I have to change all anchors/link hrefs with if conditions in twig templates with additional /pl and add all Route cases in yaml which is time-consuming.
I wouldn't like to use bundles which was suggested for older Symfony versions
Is it possible to change URL when locale is changed?
This is my route:
contact:
path: /{type}
defaults: { _controller: WebPortalBundle:Default:contact }
requirements:
type: kontakty|contact
Is it possible when locale is "en" to display url with type = contact, when russian, czech, slovak, display with type = kontaky ?
Yes, it's possible. We are using https://github.com/BeSimple/BeSimpleI18nRoutingBundle that bundle for doing that.
After installation bundle you need to open config.yml file and add this config.
be_simple_i18n_routing: ~
After that open your main routing.yml file(app/routing.yml) and simply add type "be_simple_i18n". It's shoud be like that.
acme:
resource: "#AcmeBundle/Resources/config/routing.yml"
prefix: /
type: be_simple_i18n
And finally open bundle spesific routing.yml file (in that case AcmeBundle/Resources/config/routing.yml).
acme_contact:
path: /
defaults: { _controller: AcmeBundle:Default:contact }
locales: { en: "/contact", ru: "/kontaky" }
I am using http://docs.sylius.org/en/latest/bundles/general/overriding_controllers.html as a reference when trying to override the homepage controller.
I tried the following in config.yml:
sylius_web:
driver: doctrine/orm
classes:
frontend:
homepage:
controller: SpaceDice\WebBundle\Controller\Frontend\HomepageController
And it doesn't seem to be working.
What would I put in config.yml to specify the controller from the homepage?
In: vendor/sylius/src/Sylius/Bundle/WebBundle/Resources/config/routing/main.yml I see:
sylius_homepage:
path: /
defaults: { _controller: sylius.controller.frontend.homepage:mainAction }
but I'm not sure how to override/set sylius.controller.frontend.homepage.
Thanks
I was able to figure out a couple ways to do this.
First, you can set the parameter in config.yml:
parameters:
sylius.controller.frontend.homepage.class: My\Controller\Here
Another option is to set the homepage route of / in my AppBundle/Resources/config/routing.yml
homepage:
path: /
defaults: { _controller: AppBundle:Frontend\Homepage:main }
Ensure that your routing config is processed before the Sylius WebBundle config (listed first in app/config/routing.yml) and you can take it from there.
I know it is possible to filter a route by host, like this:
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: backend.domain.com
defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }
Is it possible to alter this configuration to match multiple domains? For example:
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: backend.domain.com|dev.backend.domain.com
defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }
I'm trying to avoid setting up 2 routes for every page.
You can try placeholders in your hostname with requirements (i.e.. Symfony Documentation)
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: "{mydomaines}"
defaults: { _controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index }
requirements:
mydomaines: backend.domain.com|dev.backend.domain.com
If you read the Symfony documentation, you'd know that you need to use placeholders. For your code, it would be :
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: "{subdomain}.domain.com"
defaults:
_controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index
subdomain: backend
requirements:
subdomain: backend|dev.backend
I hope it'll help you !
EDIT :
If you want your default subdomain to be the current one, you can use a parameter like this :
irc_backend.report.stacking_issue:
path: /reports/stacking-issues
host: "{subdomain}.domain.com"
defaults:
_controller: IRCBackendBundle:Reports/Product/StackingIssueReport:index
subdomain: "%subdomain%"
requirements:
subdomain: backend|dev.backend
Then you will be able to define this parameter in an Event listener with this line of code :
$container->setParameter("subdomain", $your_subdomain);
P-S : Don't forget to add the Service container to your listener's dependencies
I have problem with setting hosts for my symfony application. For now we have one domain, let's sey it was domain.pl for all four languages. So rule in YML was:
front_common:
resource: "#FrontCommonBundle/Resources/config/routing.yml"
prefix: /{_locale}
defaults: { _locale: pl }
requirements:
_locale: "[a-z]{2}"
front_common_locale:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
_locale: pl
path: /pl
permanent: true
So if someone enters domain.pl, he/she will be redirected to domain.pl/pl. Other pages was domain.pl/en, domain.pl/de and so on...
Now we get another domain, let's say domain.eu, that should show only english version, so domain.eu show english, others still redirects to /pl /de etc. My routing now looks this way:
front_common_eu:
host: domain.eu
resource: "#FrontCommonBundle/Resources/config/routing.yml"
prefix: /
defaults: { _locale: en }
front_common:
resource: "#FrontCommonBundle/Resources/config/routing.yml"
prefix: /{_locale}
defaults: { _locale: pl }
requirements:
_locale: "[a-z]{2}"
front_common_locale:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
_locale: pl
path: /pl
permanent: true
When I enter domain.pl it works fine, and redirects me to /pl. But when I enter domain.eu it works the same, it redirects me to /pl. If I remove fron_common_locale route, I've got 404. Help, what am I doing wrong?
PS. According to this: Routing prefix as follows the Virtual Host it should work...
Replace _locale on front_common_locale with:
_locale: pl|en