2

I have a new question related to this question, but since the questions do not match at all, I am creating this new topic. But it is for good reference.


I changed my mind about the logs to log thing, logs is fine. But I am having another controller called WikisController, in this case I would really like to change the URL. I just hate it that the URL will be example.com/wikis/subject.html, I want it to be example.com/wiki/subject.html. It is much cleaner and the convention is now a 100% match with other sites where it is also called wiki, and not wikis. But, I want the controller to be called WikisController, because of the CakePHP convention.

Well, now comes the real problem. I was currently using the following routing in Config/routes.php:

Router::connect('/wiki/:action/*', array('controller' => 'wikis'));
Router::connect('/wiki/*', array('controller' => 'wikis'));

This is the piece of code used by the solution in the other topic. But now I am running into a little bit of trouble. Well, it isn't really a big issue because everything works just fine. But I don't like the URL.

When I create a link as the following from example.com/wiki/edit.html:

echo $this->Html->link('Wiki overview', array(
    'controller' => 'wikis',
    'action' => 'index',
    'ext' => 'html'
));

It is creating a link to example.com/wiki/index.html totally fine and it works, but I don't want to show the index.html, I just don't. It is a word extra in the url and it is not necessary for the user to understand where he is.

I am creating the link with the controller and action key because of a little bug I was having earlier. When I didn't specify the action, it would create a link to example.com/edit.html which I don't want, obviously. So I have to add the action => index key to the array. I am not sure if this is a real bug, but it shouldn't matter. Index = index and nothing changes that. It is a good thing that I am sure my URL is pointing to the right page, so adding the action isn't an issue for me.

Just for good notice:

When I am creating a link on exactly the same way as I did above to example.com/flights/index.html from the page example.com/flights/add.html it would delete the /index part from the url and simply create a url to example.com/flights.html which is much cleaner.

So it has to do something with the routing, but I can't figure out what.

Community
  • 1
  • 1
Jelmer
  • 2,663
  • 2
  • 27
  • 45

1 Answers1

1

If I understood you correctly, then you'll need a route that connects /wiki to the controllers index action:

Router::connect('/wiki', array('controller' => 'wikis', 'action' => 'index'));
Router::connect('/wiki/:action/*', array('controller' => 'wikis'));
...
ndm
  • 59,784
  • 9
  • 71
  • 110
  • This solution seems to work quite well. I have to test it a bit more to be 100% sure though. If it is the fix I will mark this post as the answer. Thanks :) I removed the second line of my current routing and that doesn't give any warnings or errors. So changing the second line to the first line of yours and changing the order did the trick. – Jelmer Oct 13 '12 at 19:50
  • Ok I tested it a bit and it seems to work fine. If I run in any problems after all I will let you guys know. And I will post a link to this question in the earlier question. – Jelmer Oct 16 '12 at 07:15