url routing - Symfony CMF RoutingBundle - PHPCR Route Document - Multiple Parameters -


tried find solution, got stuck docs or @ answers include other bundles. in documentation of dynamic router can find hint:

"of course can have several parameters, normal symfony routes. semantics , rules patterns, defaults , requirements same in core routes."

thats it.

...

/foo/{id}/bar

i tried (seems not) done.

same tries:

i tried apply variable pattern , child route.

use symfony\cmf\bundle\routingbundle\doctrine\phpcr\route phpcrroute;  $dm = $this->get('cmf_routing.route_provider');  $route = new phpcrroute(); $route->setposition( $dm->find( null, '/cms/routes' ), 'foo' ); $route->setvariablepattern('/{id}'); $dm->persist( $route );  $child = new phpcrroute(); $child->setposition( $route, 'bar' ); $dm->persist( $child );  $dm->flush(); 

with or without default value , requirement '/foo/bar' , '/foo/*' return matches, '/foo/1/bar' prompts me 'no route found "get /foo/1/bar"'.

...

just got done.

use symfony\cmf\bundle\routingbundle\doctrine\phpcr\route phpcrroute;  $dm = $this->get('cmf_routing.route_provider');  $route = new phpcrroute(); $route->setposition( $dm->find( null, '/cms/routes' ), 'example_route' ); $dm->persist( $route );  $route->setprefix( '/cms/routes/example_route' ); $route->setpath( '/foo/{id}/bar' );  $dm->flush(); 

if prefix '/cms/routes' , name 'foo' works fine. got far, assigning speaking name round up.

thanks in advice!

you got quite close solution, actually!

when using phpcr-odm, route document id path in repository. phpcr stores content in tree, every document needs in specific place in tree. use prefix url match. if prefix configured /cms/routes , request /foo, router looks in /cms/routes/foo. allow parameters, can use setvariablepattern correctly assumed. use case of /foo/{id}/bar, need setvariablepattern('/{id}/bar'). have setvariablepattern('/{context}/{id}') (this doc paragraph quoted meant - adding example there indeed not helpful "you can this" not explain how to).

calling setpath not recommended less explicit - noticed, job done. see phpdoc , implementation of model\route::setpattern:

/**  * recommended use setvariablepattern set part after  * static part. if use method, ensure  * static part not changed , change variable part.  *  * when using phpcr-odm, make sure persist route before calling  * have id field initialized.  */ public function setpath($pattern) {     $len = strlen($this->getstaticprefix());      if (strncmp($this->getstaticprefix(), $pattern, $len)) {         throw new \invalidargumentexception('you can not set pattern route not start current static prefix. first update static prefix or directly use setvariablepattern.');     }      return $this->setvariablepattern(substr($pattern, $len)); } 

about explicit names: repository path name of route, in example /cms/routes/foo. not idea use route name of dynamic route in code, routes supposed editable (and deletable) admin. if have route exists sure , @ specific path, use configured symfony routes (the routing.yml file). if dynamic routes, have @ cmf resource bundle. allows define role document , way documents role. if have route specific role want link controller / template, way go. if have content document linked route document , have content document available, third , best option generate url content document. cmf dynamic router can that, use content object specify route name.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -