Giter Site home page Giter Site logo

Comments (5)

dbu avatar dbu commented on July 17, 2024

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.

asiragusa avatar asiragusa commented on July 17, 2024

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.

asiragusa avatar asiragusa commented on July 17, 2024

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.

dbu avatar dbu commented on July 17, 2024

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.

asiragusa avatar asiragusa commented on July 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.