Comments (5)
i think at least the phpcr route document found in the RoutingBundle has a special option to control whether the format should be appended. see http://symfony.com/doc/master/cmf/bundles/routing/dynamic.html#the-phpcr-odm-route-document and https://github.com/symfony-cmf/RoutingBundle/blob/master/Model/Route.php#L69-L71 (you can also call setOption defined by the symfony Route class the cmf route class is extending)
could it be your route ended up not looking exactly like you expected? you could try to debug what the pattern looks like in https://github.com/symfony-cmf/Routing/blob/master/NestedMatcher/NestedMatcher.php#L141
from routing.
I tried using the add_format_pattern option and now it works for /type and for /type.html, but not for /type.json, as expected: https://github.com/symfony-cmf/RoutingBundle/blob/master/Model/Route.php#L83
$type = new Route(array(
'add_format_pattern' => true
));
$type->setPosition($parent, 'type');
$type->setContent($page);
$type->setDefault('type', 'default_type');
$dm->persist($type);
How can I make it work with json too?
from routing.
Well my question was finally dumb :)
$type = new Route(array(
'add_format_pattern' => true
));
$type->setPosition($parent, 'type');
$type->setContent($page);
$type->setDefault('type', 'default_type');
$type->setRequirement('_format', 'html|json');
By the way it would be nice to be able to express this like:
$type = new Route(array(
'add_format_pattern' => ('html', 'json')
));
//OR
$type = new Route(array(
'add_format_pattern' => ('html' => true, 'json' => true)
));
Anyway thanks a lot for your help
from routing.
glad you could solve it.
indeed, your proposal would be nice. if you want to do a PR, feel free. i would extract the pattern right in the constructor and overwrite the setOption
to handle this case, and clean the stored value to become true
, setting the format requirement automatically. and you could update the documentation over at symfony-cmf-docs to mention the possibility (i think right now we don't really explain the add_format_pattern with any example, but i might be wrong)
from routing.
Yep, it's not documented, otherwise I wouldn't have struggled ;)
At the moment I am really busy finishing the Symfony porting of my CMS, I will do the PR once I will have some free time
from routing.
Related Issues (20)
- Create content_on_method enhancer HOT 28
- Issues with conditional enhancer HOT 4
- No Deprication HOT 5
- New File Structure
- Upgrade File
- The router fails to match unicode uri HOT 5
- Attempted to load interface "ChainedRouterInterface" from namespace "Symfony\Cmf\Component\Routing". HOT 5
- Candidates::determineLocale regex matches wrongly HOT 4
- Does dynamic router works on application redirects? HOT 2
- Print dynamic routes on router:debug HOT 2
- Uninitialised requestContext leads to "Call to a member function setParameter() on null -- in LocaleListener.php" HOT 1
- fix latest 1.x HOT 1
- Wrong type hint for ChainRouter::generate HOT 3
- Redirect routes with trailing slash HOT 7
- Symfony Route is not loaded from dumped file HOT 2
- User Deprecated: Since symfony/event-dispatcher 5.1: Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy is deprecated, use the event dispatcher without the proxy. HOT 3
- split into symfony-cmf/chain-router and symfony-cmf/dynamic-router HOT 4
- simplify the dynamic router HOT 4
- TypeError for LazyRouteCollection::all() when inner route provider returns generator from getRoutesByNames() HOT 1
- Potential security issue HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from routing.