link_to() generates route successfully, but clicking on that link results in a 404

StackOverflow https://stackoverflow.com/questions/641083

  •  22-07-2019
  •  | 
  •  

Question

I've set a website up. If I try and click on a link such as register I get the following error:

404 | Not Found | sfError404Exception
Empty module and/or action after parsing the URL 
    "/trevelyan.alumni/register" (/).

The links are generated using

<?php 
    print link_to( 'Register', 'register/index' ); 
?>

And I have a 'register' module in apps/frontend/modules/register.

I'm quite new to Symfony, any help is appreciated!


routing.yml:

# default rules
homepage:
  url:   /
  param: { module: home, action: index }

default_index:
  url:   /:module
  param: { action: index }

default:
  url:   /trevelyan.alumni/:module/:action/*
Was it helpful?

Solution

I think that your problem is that you're running symfony out of a "sub-site" instead of directly off of the "root" url (http://www.dur.ac.uk/trevelyan.alumni instead of http://www.dur.ac.uk/). I think the easiest solution would be to add trevelyan.alumni to the front of all your urls in routing.yml.

For example, for the default route, instead of

default:
  url: /:module/:action/*

use

default:
  url: /trevelyan.alumni/:module/:action/*

OTHER TIPS

Read Steven Oxley, but try this as well :

Check you have at least an action class in your module dir with the proper name (symfony is case sensitive, and this is very tricky).

If you do, check that the default action (in the module config files) is one of the action class in your module.

Don't forget to clear cache every time you change a config file.

I managed to fix this by editing the symfony controller files to use the $_SERVER variables to pick a module from, if one was not found.

at the end of your routing.yml file:

homepage:
  url:   
  param: { module: main, action: index }

default:
  url:   /:module/:action/*

and don´t forget to clear the cache afterwards ;)

Just a quick note, for the routing change(s) to take effect, you must run symfony clear cache:

./symfony clear-cache

you should remove a dot from your matching url for route because of default routing rules

change your default route to:

default:
  url: /trevelyan_alumni/:module/:action/*

and that should work. note that dot(.) is replaced with _

I had upgraded from symfony 1.2 to 1.4, and was having this problem. At the end of the day, basically the config files have all changed enough to the point that routing somehow broke. Going through the app config files and comparing / updating them against the "new app" templates found in lib/vendor/symfony/lib/config/config (or where ever you are keeping symfony) fixed this issue.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top