> On Thu, Dec 30, 2010 at 10:28 AM, WhyNotSmile wrote:
>> I'm trying to create a link on my page to download a file. However,
>> the server won't let me use mod_rewrite, and I'm having problems
>> getting the download to work. I googled the problem, and made some
>> progress.
>>
>> So far, I have:
>>
>> In the view, the link to download the file is:
>>
>> <?php echo $this->Html->link('Download File', '/downloads/
>> download', array('class' => 'bluelink'));?>
>>
>> I have a controller called downloads_controller.php which contains:
>>
>> <?php
>> class DownloadsController extends AppController {
>>
>> function download () {
>> $this->view = 'Media';
>> $params = array(
>> 'id' => 'constition.pdf', // hard-coded for now
>> 'name' => 'constitution',
>> 'download' => true,
>> 'extension' => 'pdf',
>> 'path' => APP . 'files' . DS
>> );
>> $this->set($params);
>> }
>> }
>>
>> The file is in the directory 'app/files'.
>>
>> When I click on the link in the view I get:
>>
>> Not Found
>>
>> Error: The requested address '/downloads/download' was not found
>> on this server.
>>
>> Does anyone have any ideas as to what else I should be doing?
>
> Set debug to 2 in core.php. Cake throws a 404 when it encounters an
> error and is in production mode.
Yes.... but if he doesn't have mod_rewrite, then it sounds like it's the web server, and not CakePHP, that's generating the 404 error. The web server, without mod_rewrite, will simply expect there to be a file or directory "download" inside the directory "downloads" in the document root, and this of course doesn't exist, hence the 404.
Why are you writing the link URL as '/downloads/download'? Shouldn't you write it as array('controller' => 'downloads', 'action' => 'download')? That way, CakePHP would construct a URL that's appropriate to your situation.
I assume you've already followed this advice from app/config/core.php:
/**
* To configure CakePHP *not* to use mod_rewrite and to
* use CakePHP pretty URLs, remove these .htaccess
* files:
*
* /.htaccess
* /app/.htaccess
* /app/webroot/.htaccess
*
* And uncomment the App.baseUrl below:
*/
//Configure::write('App.baseUrl', env('SCRIPT_NAME'));
P.S: "bluelink" is a horrible name for a CSS class. What if your designer later decides the link will be orange? Then you have a CSS class called "bluelink" that actually makes text orange. Or worse, you have to find and replace "bluelink" with "orangelink" everywhere in your source, and hope you don't miss any occurrences. No, a much better name for the CSS class would be "download-link" or "special-link" or whatever wording describes *why* this link gets a special style (and not its current visual appearance).
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment