tags:

views:

1923

answers:

9

I'd like to link to some PDFs in one of my controller views. What's the best practice for accomplishing this? The CakePHP webroot folder contains a ./files/ subfolder, I am confounded by trying to link to it without using "magic" pathnames in my href (e.g. "/path/to/my/webroot/files/myfile.pdf").

What are my options?

EDIT: I didn't adequately describe my question. I was attempting to link to files in /app/webroot/files/ in a platform-agnostic (ie. no mod_rewrite) way.

I've since worked around this issue by storing such files outside the CakePHP directory structure.

+1  A: 

I'm not sure I understand the question correctly, but here goes. Basically any file you put in the webroot folder will be accessible on the webserver, so if you put the file in webroot/files/file.pdf you would simply link to /files/file.pdf.

If that doesn't work, please clarify your question...

Jonas Due Vesterheden
+4  A: 
$html->link('Pdf', '/files/myfile.pdf');
Alexander Morland
This is, strictly, the correct answer to my question. However, I didn't communicate well that I was struggling with linking to files in the /app/webroot/files directory across multiple platforms; specifically, where mod_rewrite isn't available...
Daniel Wright
A: 

or...

<a href="<?php echo $html->url('/files/somefile.pdf'); ?>">Link Text</a>
Chris Hawes
A: 

or..

<a href="<?php echo $this->webroot; ?>files/somefile.pdf">Link Text</a>

:)

A: 

Hi,

hope, somebody can help me. Maybe it is a rookie question, but if i try to link a Word 2007 File with the file extension

docx

i became a missing_controller

Error: FilesController could not be found

and if i link to a doc file it happens well. Below you can see see link. I am using cakeph 1.2 running on xampp

<?=$html->link($offer['path'], "/files/".   $offer['path'])?>
A: 

If I would like to link to a file from controller ?

alexgenovese
A: 

I can confirm that this is an issue when mod_rewrite is not being used.

<?php echo $html->link('pdf', '/files/test.pdf'); ?>

outputs

<a href="/pathtoapp/index.php/files/test.pdf">pdf</a>

it should output

<a href="/pathtoapp/app/webroot/files/test.pdf">pdf</a>
James Revillini
A: 

This should work

<?php echo $html->link('pdf', $this->webroot('files'.DS.'test.pdf'); ?>
sotomsa