0
votes

I've a pdf document in my CAKEPHP webroot. I want to create a route to that pdf file with the name /mydoc. I'm using CAKEPHP 1.3

When we type example.com/mydoc it should open that pdf.

Any direct ways to write direct route and it will be achieved without using controller and action.

2
Is this a dynamically generated file or a static one?Ian Hunter
Static one. As i've mentioned "I've a pdf document in my CAKEPHP webroot"Vins
Its not the right way if you are going to try without a controller.if you are ready ro follow framework flow then >use this trick .Make a controller of any name and you can controll it from there...try thishttp://book.cakephp.org/1.3/en/view/952/File-extensionsjack

2 Answers

3
votes

If you're using a route, this will have to invoke a controller, in which you may output the PDF using a Cake Media View. That seems rather like overkill though. Instead, just add a URL rewrite rule to app/webroot/.htaccess:

RewriteRule ^/mydoc$ files/the_file.pdf

(Untested, may need some fiddling.) This way the file download is handled by the webserver directly without having to go through Cake.

2
votes

As of CakePHP 2.9, you can put the following in your routes.php file.

Router::redirect('/mydoc', 'files/mydoc.pdf');