CakePHP how to create a route for a pdf file - cakephp

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.

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.

As of CakePHP 2.9, you can put the following in your routes.php file.
Router::redirect('/mydoc', 'files/mydoc.pdf');

Related

cakephp 3 Bypassing a specific folder in webroot without using .htaccess

I have a specific folder containing ViewerJS that I want to bypass without using .htaccess
The path I want to work is /ViewerJS/#/files/viewfile/version where version is some integer.
The action viewerJS is not defined in AppController
Error: Create AppController::viewerJS() in file: src/Controller/AppController.php.
Is there any way to achieve this using CakePHP routing? I have managed to get this working before with .htaccess but would much prefer a native CakePHP way.
It's really just a way to tell CakePHP to not try to find a controller etc and just treat it as a direct link.

CakePHP HTMLHelper for Scripts uses extra param in URL causing scripts not to load

For our project we've been using a lot of subdomains, but for one particular section we just use a redirect that sends the user of a specific type from the normal dashboard at /dashboard to /manager/dashboard.
This has been in place for months and works, but now in an element within our view we're trying to load some scripts using the HTMLHelper, but it's appending the /manager to the URL.
How can I have it just access the webroot version at
/js/path
instead of
/manager/js/path
using a generic element that is used throughout our application in different subdomains like it doesn't now (with the exception of /manager/*?
Try adding
Configure::write('App.jsBaseUrl','js/');
to your bootstrap.php file.
Alternatively, if you provide the full path to the .js file (starting with a leading /), CakePHP will ignore whatever App.jsBaseUrl holds, and will render the correct path.

CakePHP: Can only load index.php, all pages 404 after Cake Bake

I'm trying to bake my first CakePHP application and am unable to get any page to particularly load for me right now. I've updated my config settings for salt,database, etc. and the index.php page tells me that I have configured everything.
So far I've used cake bake all on just one database table so far to make sure it loads properly. I created the Model, Controller, and View for the standard add/index/view/edit pages. When I try to access URL/organizations/index.php I'm hitting a 404 error however.
Is there any troubleshooting someone might have advice for how to solve this one? It is confusing to me that the index.php loads (so it redirects properly when loading the webroot) but trying to view any View pages yields no results. Is there any debug commands I can do to view what the valid pages would be? Or any additional information I can provide?
If you try URL/index.php/organisations or something similar to this and it works, then there is an issue with URL re-writing on the server which you'll need to correct.
I believe if you have things set up correctly you would want to visit /organizations in order to access the index() method of the organizations controller.
In general the ".php" is left off of the URL, as your index.php file initiates all the bootstrapping and routing. This also requires a correct .htaccess setup. Hard to say exactly what the problem is without seeing the app or an error message.
Try in url
URL/organizations/index.php
To
URL/organizations/index
or
URL/organizations/index.ctp
Cakephp using .ctp extension, that means cakephp Template. Please see this link. And also you can see your app\view\Organizations folder. Here all file is with .ctp extension. Isn't it ?

Whta if I don't use app/webroot/index.php

I know that the index.php requires many files like core,dispatch,bootstrap and so on.This time in my project,I directly use a html inseide which has a ,and
the href is "topath/app/houses/init"(created by myself).The question is that,how about the index.php and the files it requires?Should they be required actually?
Thank you very much.
yes index.php required those files to load cake api, and dispatcher api's.
if you need a plain html then you can use following structure
topath/app/index.html which contain anchor tag to redirect on your
specified app
topath/app/houses is an cakephp app that contains all your houses app
content
if you have multiple cakephp app then you can seperate cake api
keep cake api out side from app
mainapp/cake/ include all cakephp api lib
mainapp/houses/ include all houses app code
update mainapp/houses/app/webroot/index.php to load cake api from
mainapp/cake/
and so on......
hope it will help you

Is there anything wrong with using html files without the ".html" extension?

I was wondering if there is anything wrong with using html and php files without extensions.
For example, if I was to upload a file with an extension, I would get to by using a URL like this:
http://yoursite.com/randompage.html
If I used a file without an extension, I would use a URL like this:
http://yoursite.com/randompage
I know that this can't be the preferred method because it leaves the file without a way to be identified, but is there anything that would stop the site from working properly?
What you want to do is done with url-rewriting .
Basically, you will add a rewrite rule to your web server, so when he receives a request for url yoursite.com/randompage he will change it to yoursite.com/randompage.html. You will find a lot of examples on the web if you google for "mod_rewrite examples" or "url rewrite examples".
Document types are sent from the webserver in http headers, so it is perfectly possible to do what you are asking.
For instance when using Apache, to tell it that any file with no extension is html, in the 'conf' file you can say:
DefaultType text/html
More details at Apache The Definitive Guide
This point to concrete document (randompage.html in this case):
http://yoursite.com/randompage.html
This point to default document in directory:
http://yoursite.com/randompage/
Default document is set in you webserver. This could be for example: index.html, default.html, index.php, default.apsx,...

Resources