How to define symfony routes with seperating "-" between 2 parameters? - symfony

I have a symfony routing defined:
route_name:
path: /foo/{slug}-{jobId}
slug: can be bar-92-test-123
jobId: integer
What are the right regular expressions for slug and jobId for Symfony to handle the route correctly?

Normally the following regular expression can cover your need:
(.*)-(\d+)$
So it seems the last $ sign can solve your issue as well.

It works with the following requirements:
requirements:
slug: '([a-z0-9]+[-]?)+'
jobId: '\d+'

Related

What "resource: |" does mean in routes.yaml?

I'm trying to figure out with Sylius routing, based on Symfony framework. I found that code
sylius_admin_channel:
resource: |
alias: sylius.channel
section: admin
templates: "#SyliusAdmin\\Crud"
except: ['show']
redirect: update
grid: sylius_admin_channel
permission: true
vars:
all:
subheader: sylius.ui.configure_channels_available_in_your_store
templates:
form: "#SyliusAdmin/Channel/_form.html.twig"
index:
icon: share alternate
type: sylius.resource
But I could not find any information what is it | for resource. Any help?
Thanks.
It's the YAML syntax for a multi-line string (that preserves newlines).
So sylius_admin_channel is a mapping that has two keys (resource and type) whose values are both string types.
It can be confusing to see in this instance because the string happens to also be valid YAML. I edited your question to include syntax highlighting for YAML which makes this a little more obvious, visually.
If I didn't know any better, I would have guessed that the | is there in error and resource should actually have a mapping type for its value. If you remove the |, then same symbols that were within that string still produce valid YAML for the whole file, but the value of resource would be a mapping, rather than a string.
Notice the difference in syntax highlighting, compared to the yaml in the question with the | removed:
sylius_admin_channel:
resource:
alias: sylius.channel
section: admin
templates: "#SyliusAdmin\\Crud"
except: ['show']
redirect: update
grid: sylius_admin_channel
permission: true
vars:
all:
subheader: sylius.ui.configure_channels_available_in_your_store
templates:
form: "#SyliusAdmin/Channel/_form.html.twig"
index:
icon: share alternate
type: sylius.resource

Products sorting on indexByTaxon page

I'm trying to add ability to sort products by price and date. Are there any predefined methods to do that, or the only way is to implement them by hand? From sylius.yml we're getting such strange route:
%sylius.model.taxon.class%:
field: permalink
prefix: /t
defaults:
controller: sylius.controller.product:indexByTaxonAction
sylius:
template: SyliusWebBundle:Frontend/Product:indexByTaxon.html.twig
Which can be used like {{ path(taxon) }}. But just adding sorting parameter doesn't work for me. Any ideas?
You need a version, which incorporates the Pull Request #2122. Either the latest master, or you fork the 0.11 branch and cherry pick this fix.
Then you can simply define in your config.yml to only override the required defaults:
sylius_core:
routing:
%sylius.model.taxon.class%:
defaults:
sylius:
sorting:
order: desc

Cannot import resource error, FosRestBundle Throws InvalidArgumentException

Hello i have a strange problem, while using FostRestBundle.
First error is :
InvalidArgumentException: Every parent controller must have get{SINGULAR}Action($id) method
where {SINGULAR} is a singular form of associated object
And the second one :
Cannot import resource "/home/a15net/public_html/game/src/ATL/ContentBundle/Resources/config/api_routing.yml" from "/home/a15net/public_html/game/app/config/routing.yml".
I'v checked my all "YAML" files but there was no indent problems.
Tried to update composer twice nothing helped.
Edit : Config.yml > http://goo.gl/dqCAu
You have to remove the 'type' from this import statement fro your routing.yml
atl_content_api:
resource: "#ATLContentBundle/Resources/config/api_routing.yml"
Inside the api_routing.yml you can specify the rest type for each controller like,
acme_user_rest:
resource: Acme\UserBundle\Controller\UserRestController
prefix: /api
type: rest
this blog will help you to implement the sme
--- NOT --- SOLUTION :
If a route has a parent route, you must not put "type:rest" to it. You have to use "type:rest" only in parent routes.
Sample :
catalogs:
type: rest
prefix: api
resource: ATL\CatalogBundle\Controller\API\CatalogsController
options:
expose: true
taxonomy:
parent: catalogs
resource: ATL\CatalogBundle\Controller\API\TaxonomyController
options:
expose: true
I will not choose this as correct answer until more comments and other solution suggestions writed.
Edit
When you remove type:rest from children route, it is not a rest route anymore.

Searching through multilingual records using ElasticaBundle & Translatable

I've created a multi-lingual website with Symfony2 using the (Gedmo) Translatable behavior extension for Doctrine2. This works fine but now i'm looking for a way to use the ElasticaBundle to create a nice searchoption. I want German users to search in the German-translation but also in the English translation.
At the moment i'm trying to use separate indexes for each language. My config.yml looks like this:
foq_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
articles_en:
client:default
types:
article:
mappings:
name: { boost: 5, analyzer: my_analyzer }
persistence:
driver: orm
model: Test\SiteBundle\Entity\Article
identifier: id
provider:
service: elastica.translation.provider.article.en
finder:
articles_de:
....
articles_nl:
.....
This works fine if you want to search through one index but searching two indexes seems not possible with this bundle or am I wrong?
Is there a way to do this? Any help will be appreciated!
Rick
You should probably just add one index for every article in every language and add a language to your index. You can then search your index for articles in one or more languages.

Symfony2 routing repeating pattern

I have a URL that can accept any number of parameters but not in exactly the same order. For example
example.com/myapp/service1/username1/service2/username2
or
example.com/myapp/service2/username2/service1/username1
or
example.com/myapp/service7/username7
How can I write a rounting yml entry to catch any of those routes so that I can split them into service/username for example array("service" => "Instagram", "username" => "JoBloggs") or how ever many were passed to the URL.
I have access to a pre-made list of about 30 services, but usernames could pretty much be any value.
I'm not really sure even how to ask this question so I'll give any additional info that would be useful.
Ideally, I'd like to avoid something like example.com/myapp/?service1=username1&...
Seems like I can add mimic catch all at the end of a URL Slash in parameter
route_name:
pattern: /myapp/{services}
defaults: { _controller: bundle.controller.homepage:index }
requirements:
services: ".+"

Resources