0

Since 2.1.4 the Query route is deprecated, I'm routing to my blog like this:

        'cro-blog' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/blog',
                'defaults' => array(
                    'controller' => 'CroBlog\BlogController',
                    'action'     => 'index',
                ),
            ),
        ),

And link to pages like /blog?p=x where x is the page number. This works perfectly until I add a child route. Linking to /blog still works but linking to pages give a 404 (more specific 'The requested URL could not be matched by routing.'). This is my current setup:

        'cro-blog' => array(
            'type' => 'Literal',
            'options' => array(
                'route' => '/blog',
                'defaults' => array(
                    'controller' => 'CroBlog\BlogController',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'post' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' => '/:slug',
                        'constraints' => array(
                            'slug' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                            'action' => 'post',
                        ),
                    ),
                ),
            ),
        ),

I'm using a Segment child route but the same problem exists with a Literal child route.

Any way to keep the page query and the child routes?

  • I can't reproduce this locally, using `Blog` in a view and following the link doesn't give a 404. Maybe I'm missing something :-/ – Crisp Mar 28 '13 at 11:48
  • Your comment brings me to another issue I forgot to mention. Using the URL view helper like that (with the query option), doesn't work for me. It echoes '/blog', ignoring the query. I ended up adding the query using string concatenation and forgot about it. – CrocoDillon Mar 28 '13 at 12:05
  • Odd, and you're sure you're constructing it the same way, with query contained in the third param? Maybe copy/paste mine to test. Seems like other forces at work somewhere for the url helper to also not be working as expected. Obvious question, but have you tried updating ZF2 just to be sure it's in sync. – Crisp Mar 28 '13 at 12:22
  • I copy pasted from your comment to test, echoed `Blog`. Just deleted the whole Zend directory again and downloaded a fresh one, same issues. My mind is puzzled :( The application is built on the Skeleton application from previous release (I think 2.1), could it be some config thing? – CrocoDillon Mar 28 '13 at 12:26
  • The skeleton app I'm using started out as 2.0.4 and is currently at 2.1.4 so I doubt it's a legacy issue. Hard to know if it's a config problem, maybe do a clean install of the skeleton app for testing, and see if the issue persists when you try it with that. – Crisp Mar 28 '13 at 12:37
  • Created a fresh Skeleton App (using Zend Studio 10), added `Home Query test` to index.phtml, echoed `Home Query test`, again without query. – CrocoDillon Mar 28 '13 at 13:09
  • Then I'm stumped I'm afraid, maybe someone else will come along who's had the same problem and has a solution, but without being able to reproduce it's difficult to debug. In the meantime maybe hit the zend irc channel and ask there? – Crisp Mar 28 '13 at 13:24
  • I just tried it on my old laptop and there it works as expected (Windows 7, Apache 2.2.21 and PHP 5.3.8... my current laptop runs Windows 8, Apache 2.2.22 and PHP 5.3.13). I really hope someone else will come along. Thanks for trying anyway! :) – CrocoDillon Mar 28 '13 at 14:11
  • 1
    Turned out to be a weird cache issue, I've posted what I did that eventually solved this as an answer in case anyone ever has the same issue even though I'm not sure why it worked. Thanks a lot for the help! :) – CrocoDillon Mar 28 '13 at 23:19

1 Answers1

0

This is solved. If anyone experiences the same issues, this is what worked for me.

  • Clear all cache (EdpSuperluminal, APC etc.)
  • Remove Zend library
  • Run your application without Zend library (giving loads of errors of course, but this seemed crucial to me to make it work)
  • Re-install Zend library
  • Run your application again

I installed 2.1.5dev and it fixed the issue. Wanted to make sure whether it was a bug or not so tried again with 2.1.4 and the issue was still fixed. So this is my conclusion. Cache can be a weird thing.

Edit Jumped to (the wrong) conclusions too soon. Fired up Zend Studio 10 and now it bugs again. I think Zend Studio 10 is reverting some files (not all since Query route did got marked as deprecated). Still, consider this solved, just need to find a way to tell Zend Studio 10 to use 2.1.4. Thanks!