symfony-cmf / routing-bundle

Symfony bundle to provide the CMF chain router to handle multiple routers, and the dynamic router to load routes from a database or other sources.
160 stars 78 forks source link

/routes wont be removed from urls #114

Closed digitalkaoz closed 11 years ago

digitalkaoz commented 11 years ago

Hey i am using beta-1 of the symfony-cmf standard edition. and i like it very much :) thanks for the good work!

here is my problem:

nodes dump

ROOT:
  cms:
    routes:
      home:
    menu:
      home:
    content:
      static:
      home:

routing.yml

home_redirect:
    pattern: /
    defaults:
        _controller: FrameworkBundle:Redirect:redirect
        route: /cms/routes/home
        permanent: true

config.yml

cmf_routing:
#    route_basepath: /cms/routes
    dynamic:
        enabled: true
    chain:
        routers_by_id:
            cmf_routing.dynamic_router: 20
            router.default: 100

if i try to access / in my browser i am redirected to /routes/home, that /routes/ is to much. if i try to access /home i am getting a 404...

how to remove the routes/prefix? even if i try to set the route_basepath to /cms/routes it wont work.

any hints?

lsmith77 commented 11 years ago

hmm this seems to work fine in the CMF SE, since you used that as the basis .. the question is what did you modify in the configuration? or did you just modify the data?

digitalkaoz commented 11 years ago

mh, i modified both, data and content.

i created a gist with everything related: https://gist.github.com/digitalkaoz/5807169

maybe it could help. which class handles the prefix removal?

lsmith77 commented 11 years ago

This is done in RouteProvider. Essentially what the RouteProvider does is take the url path and prefix it with the base path.

I wonder why you even have SimpleCmsBundle configured as you dont seem to be using it. note that SimpleCmsBundle has its own base path setting which defaults to /cms/simple. See app/console config:dump-reference cmf_simple_cms.

lsmith77 commented 11 years ago

@dbu maybe you have an idea what could possibly be wrong here.

digitalkaoz commented 11 years ago

ok ive configured the simple cms and its seems the same problem, ive configured the basepath with /cms/content and all my pages have an uri like /content/foo.

i will take a look into route-provider...there seems something fundamentally wrong in my routing setup :/

lsmith77 commented 11 years ago

thanks for investigating .. you might also want to look at the cmf-sandbox for some inspiration.

dbu commented 11 years ago

sounds really strange. you are completely sure you have the routes where you think you have them and not in /cms/routes/routes right? look at the idprefix code and dump things to see what is going on. if you had /cms/routes/home in the url i would say the prefix thing might just not work, but aparently it does something but not the right thing. can you try to disable simplecmsbundle completely (not loading it in the kernel) to see if that changes anything?

digitalkaoz commented 11 years ago

mh strange...if i disable CmfSimpleCmsBundle completly, everything works! now the prefix is gone i didnt created my content with the simple cms admin.

i've created the main nodes with node:touch and created content, menu, routing with their own dedicated admins...

i`ve done that because content created with the simple-cms bundle doesnt creates a menu entry or route entry in my tree. but its routable, so i think its stored somehow inside the Page Document?

dbu commented 11 years ago

what is the base_path of the simple cms bundle? does it overlap with the base_path of the routing bundle?

btw, creating the main nodes should happen automatically when you execute doctrine:phpcr:repository:init i think.

the simplcms content puts route, menu and actual content all into the same document. if you have multilang, your urls can not be translated then, and the menu structure must be the same as the content structure and the url tree of course is then the same as well. but for simple use cases, thats all rather convenient.

digitalkaoz commented 11 years ago

i tried both, different base_path's and different once. there is no difference, if i enable the simplecms bundle all routes are prefixed

dbu commented 11 years ago

did the issue go away with the new beta2 tags?

digitalkaoz commented 11 years ago

i'll check it this weekend

digitalkaoz commented 11 years ago

nope the problem still exists...

without CmfSimpleCmsBundle all routes are correct, with all routes must be prefixed with routes/ to be accessable in the front controller

dbu commented 11 years ago

i trust you updated the versions in composer.json?

when you take the cmf standard edition and just plug in your configuration, is the issue still there? do you find any differences in the routing configuration between your project and standard edition https://github.com/symfony-cmf/symfony-cmf-standard/?

dbu commented 11 years ago

ping

lsmith77 commented 11 years ago

ping once more

digitalkaoz commented 11 years ago

sorry i didnt found the time yet, will try it on the weekend and leave feedback here...

digitalkaoz commented 11 years ago

so, i bumped my deps to beta3...now its even "worse"...with simplecms the router looks for routes under cms/simple but they resist in cms/routes without it cant find any of my routes :( i think something is fundamentally wrong...

here is the application, maybe you wanna take a look on your own? https://github.com/digitalkaoz/digitalkaoz.net i think i tried every configuration variant, none of them seemed to work :/

lsmith77 commented 11 years ago

are you sure you adjusted the configuration properly?

since you have a custom path you need to configure it as follows if you use current master or the last beta release:

cmf_simple_cms:
  basepath: /cms/routes
dbu commented 11 years ago

ehm, lukas if the simple cms is at "/cms/routes" and RoutingBundle activated and not configured differently, its at "/cms/routes". this will collide.

lsmith77 commented 11 years ago

yeah .. but this has always been the case.

dbu commented 11 years ago

which could explain why digitalkaoz had a problem since a longer time... @digitalkaoz so did you configure simplecms to read the routes from the same location as the routing bundle? this will not work, it needs to distinguish the two types of route sources.

digitalkaoz commented 11 years ago

mh if i disable the cmf_routing configuration and uncomment the cmf_simple_cms stuff, creating a page under /cms/simple works, and the routing is correct.

but if i am unwilling to use SimpleCMS nothing seems to work, i can create static-content menu and routes but the routing wont work without simple-cms :/ any hints?

lsmith77 commented 11 years ago

ok .. i think we got a bit confused there with the SimpleCmsBundle. so remove it entirely from your kernel and configuration. where are the fixtures you are loading? https://github.com/digitalkaoz/digitalkaoz.net/blob/master/src/Acme/MainBundle/DataFixtures/PHPCR/LoadSimpleCmsData.php this is all about SimpleCmsBundle

digitalkaoz commented 11 years ago

i dont load any fixtures, i create the documents by hand...

currently i am trying to get the cmf-standard-edition and sonata-admin working, to prove the issue...

another question along: SimpleCms PageDocuments cant have ChildBlocks like the StaticContent Document right?

lsmith77 commented 11 years ago

They can .. we simply do not have any examples of this and we do not have a default mapping for the children in the model. But generally any PHPCR node can have children and the rendering of blocks is done via a relative path of the content document associated with the matched route or via an absolute path.

lsmith77 commented 11 years ago

how are things looking?

digitalkaoz commented 11 years ago

i still dont get it right...

i've created a route /cms/routes/home with sonata admin, everything looks fine, but if i configure my homepage / to redirect to this route:

home_redirect:
    pattern: /
    defaults:
        _controller: FrameworkBundle:Redirect:redirect
        route: /cms/routes/home
        permanent: true # this for 301

it redirects to home but says:

No route found for "GET /home" oO what might goes wrong here? i dont get it...i want to use static-content-documents because i want to use blocks (currently not implemented for simple-cms-documents)

ROOT:
  cms:
    simple:
      about:
      contact:
        map:
        team:
      dynamic:
      docs:
      demo:
      demo_redirect:
      hardcoded_dynamic:
      hardcoded_static:
    content:
      static:
      home:
        phpcr_locale:de:
    menu:
    routes:
      home:

i am using a fresh cmf-standart-edition and plugged in the sonata backend...btw why isnt that bundled/configured for the SE?

lsmith77 commented 11 years ago

we wanted to keep the SE "simple" and didn't want to pre-configure too much. the sandbox is there for the "kitchen sink" use cases.

now let me clarify once more, SimpleCmsBundle does not preclude the use of Blocks .. Blocks can either be referenced in templates with absolute paths or relative paths and both options are also available with SimpleCmsBundle. here is an example of relative path: https://github.com/symfony-cmf/cmf-sandbox/blob/master/src/Sandbox/MainBundle/Resources/views/Homepage/index.html.twig#L14

For this to work all you need to have is for the cmfMainContent document to have a child named additionalInfoBlock. Alternatively one could also write /cms/block/foo/bar and point to a block via an absolute path.

Now getting back to the actual issue. can you paste the following for me:

app/console doctrine:phpcr:node:dump /cms/routes/home --props
app/console doctrine:phpcr:node:dump /cms/content/home --props
digitalkaoz commented 11 years ago

ah ok, so i simply create a additionalInfo block under my simple-cms-documents and can render them directly in my template? i thought i must be like: https://github.com/symfony-cmf/ContentBundle/blob/master/Model/StaticContent.php#L89

i`ll try that out...

here the dumps:

app/console doctrine:phpcr:node:dump /cms/routes/home --props

home:
  - jcr:primaryType = nt:unstructured
  - jcr:mixinTypes = Array(    [0] => phpcr:managed    [1] => mix:referenceable)
  - phpcr:class = Symfony\Cmf\Bundle\RoutingBundle\Doctrine\Phpcr\Route
  - phpcr:classparents = Array(    [0] => Symfony\Component\Routing\Route    [1] => Symfony\Cmf\Bundle\RoutingBundle\Model\Route)
  - jcr:uuid = 80175eca-0522-4bbb-a98a-4c8828b003e1
  - host =
  - defaultsKeys = Array(    [0] => _template)
  - defaults = Array(    [0] => AcmeMainBundle:Demo:dynamic.html.twig)
  - requirements = Array()
  - options = Array()
  - addFormatPattern =
  - addTrailingSlash =
  - routeContent =
   - : 9334aa46-4eb5-4abd-9f9d-842dc1180598

app/console doctrine:phpcr:node:dump /cms/content/home --props

home:
  - jcr:primaryType = nt:unstructured
  - jcr:mixinTypes = Array(    [0] => phpcr:managed    [1] => mix:referenceable)
  - phpcr:class = Symfony\Cmf\Bundle\ContentBundle\Doctrine\Phpcr\StaticContent
  - phpcr:classparents = Array(    [0] => Symfony\Cmf\Bundle\ContentBundle\Model\StaticContentBase    [1] => Symfony\Cmf\Bundle\ContentBundle\...
  - jcr:uuid = 9334aa46-4eb5-4abd-9f9d-842dc1180598
  - publishable = 1
  phpcr_locale:de:
    - jcr:primaryType = nt:unstructured
    - title = Home
    - body = die Startseite
    - tags = Array()
lsmith77 commented 11 years ago

hmm .. that looks quite ok. is the request that leads to the 404 using the locale de? if not .. how is your language fallback for phpcr odm configured in your config.yml?

lsmith77 commented 11 years ago

would it be possible for you to push your code somewhere so that I can debug it?

digitalkaoz commented 11 years ago

i simply call / (301) and i get redirected to /home (404)

my odm config:

    odm:
        auto_mapping: true
        auto_generate_proxy_classes: %kernel.debug%
        locales:
            en:
                - de
            de:
                - en

sure thing, ill push it, gimme a minute :)

lsmith77 commented 11 years ago

will probably not get around to testing it until tomorrow evening. just about to wrap up releasing updates to all the cmf bundles and then I need to get some sleep.

digitalkaoz commented 11 years ago

here is the repo https://github.com/digitalkaoz/digitalkaoz.net, no stress, i am busy myself ;)

you need to create /cms/routes and /cms/content yourself, then create a route home and link it to the static content home

but: thanks for the great affort on pushing cmf things forward :) i wish i had time to contribute, really like to play around with it :/

lsmith77 commented 11 years ago

https://github.com/digitalkaoz/digitalkaoz.net/pull/1