kicaj
kicaj

Reputation: 2968

CakePHP 2 path to webroot dir

How to create $this->Html->link(); to download file from Plugin webroot directory?

It's possible?

Upvotes: 0

Views: 1176

Answers (2)

AD7six
AD7six

Reputation: 66388

Prefix with the plugin name

As mentioned in the docs, you can download plugin assets if the request url is prefixed with the plugin name (lower cased and underscored):

Simply prepend /plugin_name/ to the beginning of a request for an asset within that plugin, and it will work as if the asset were in your application’s webroot.

Note however that if the file is intended to be public it's a better idea for the asset to actually be in the webroot:

But keep in mind that handling static assets, such as images, Javascript and CSS files of plugins, through the Dispatcher is incredibly inefficient. It is strongly recommended to symlink them for production. For example like this:

ln -s app/Plugin/YourPlugin/webroot app/webroot/your_plugin

This would make it possible to access all files in a plugin's webroot directly without any rewrite or php logic being involved.

Upvotes: 1

Fury
Fury

Reputation: 4776

Why do you have to put the file in Plugin folder to be downloaded. This is not a good practice. Keep the file in webroot/file/name_of_folder

to get the path to webroot/ simply:

debug(WEBROOT);

Upvotes: 1

Related Questions