1

I have a legacy application built in CakePHP 2.2.3

One part of the application has controller file which has been named SymposiumsController.php. This resulted in URL's such as:

domain.com/symposiums
domain.com/symposiums/view/23

The problem is that 'symposiums' isn't a real (English language) word; it should be 'symposia'.

I want to rename my URL's so they are like this:
domain.com/symposia
domain.com/symposia/view/23

I tried to do this by editing app/Config/Routes.php to use this:

Router::connect('symposia/:action', array('controller' => 'symposiums'));

However all this does is redirects domain.com/symposia to domain.com/symposiums which therefore makes no difference to what the user sees in the URL.

To put it simply I don't want 'symposiums' exposed anywhere in my URLs. I want them all to use 'symposia' in it's place.

I read http://book.cakephp.org/2.0/en/development/routing.html but can't see how to do this. Does anyone have a solution? Surely I don't have to rename controllers/models and DB tables to do this?

I don't know if this makes a difference but I also have admin routing switched on so my SymposiumsController.php also has functions such as:

admin_add()
admin_delete()
admin_edit($id)

Any help is appreciated.

6
  • Try setting the name property in the controller, I believe the Router honours that name. Commented Oct 28, 2015 at 10:35
  • @Oldskool thanks. I tried this but unforutantely it gave an error: Missing View Error: The view for SymposiumsController::index() was not found. Error: Confirm you have created the file: app/View/Symposia/index.ctp Also tried to rename my 'Symposiums' view directory to 'Symposia' and that just then redirects back to URL's like domain.com/symposiums - which is the orignal problem Commented Oct 28, 2015 at 10:41
  • The old route may still be in the cache, try clearing that as well. Commented Oct 28, 2015 at 11:01
  • Caching is switched off in the application. I have Configure::write('Cache.disable', true); set in my config file. Commented Oct 28, 2015 at 11:03
  • Router::connect('symposia missing / in front of symposia? Commented Oct 28, 2015 at 11:15

1 Answer 1

1

Here is the code for this specific redirection:

Router::connect('/:controller/:action/:id',
   array('controller' => 'symposiums', 'action' => 'view', 1)
);

:controller => Give the name new name of controller e.g. symposia
:action => Give the name new name of action  e.g. view
:id => Give the name new name of controller e.g. 23

But if you need to redirect more than one action then I suggest you to rename the controller.

Note: If you rename the controller or create new Routers then you would need to make sure in the all application modify the link to new controller name.

Source: Cakephp Router

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.