duanlanqian9974 2015-10-28 10:31
浏览 33
已采纳

CakePHP - 更改URL中的控制器名称

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.

  • 写回答

1条回答 默认 最新

  • dscizpq790832708 2015-10-28 12:39
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line