Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

php - How can I append .html to all my URLs in cakephp?

I am using cakephp in one of my projects and my client wants the site URLs to end with .html and not the usual friendly urls. I was wondering if its possible in cakephp to do so through any of its routing techniques. Please help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

That is well documented in the cookbook.

UPDATE: http://book.cakephp.org/2.0/en/development/routing.html#file-extensions

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

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

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')
    )
);

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

$this->Html->link(
    'Link title',
    array('controller' => 'pages', 'action' => 'view', 
          'title' => 'super-article', 'ext' => 'html')
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...