Welcome to the Cookbook

loading...

3.4.5.7 File extensions

このセクションには保留されている変更があります. More information about translations

To handle different file extensions with your routes, you need one extra line in your routes config file:

Router::parseExtensions('html', 'rss');
  1. Router::parseExtensions('html', 'rss');

This will tell the router to remove any matching file extensions, and then parse what remains.

If you want to create a URL such as /page/title-of-page.html you would create your route as illustrated below:

	Router::connect(
		'/page/:title',
		array('controller' => 'pages', 'action' => 'view'),
		array(
			'pass' => array('title')
		)
	);	
  1. Router::connect(
  2. '/page/:title',
  3. array('controller' => 'pages', 'action' => 'view'),
  4. array(
  5. 'pass' => array('title')
  6. )
  7. );

Then to create links which map back to the routes simply use:

$html->link('Link title', array('controller' => 'pages', 'action' => 'view', 'title' => Inflector::slug('text to slug', '-'), 'ext' => 'html'))
  1. $html->link('Link title', array('controller' => 'pages', 'action' => 'view', 'title' => Inflector::slug('text to slug', '-'), 'ext' => 'html'))