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

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.

Related

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 ?

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,...

CakePHP how to create a route for a pdf file

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');

How to do good custom routing with CakePHP?

I am planning to rewrite my site into CakePHP and after having spent a full week on learning it, I am still not sure how to do good custom routing in CakePHP.
This is what I want:
Keep the current url structure in www.domain.tld/en/dragons.html, or use a www.domain.tld/en/dragons, but not www.domain.tld/en/nodes/dragons.html. And also be able to use controllers on a similar path structure.
There are about 100 static pages on the entire site. I have read into multi-language routing and I think I can do it. I can also make /en/* or /en/:slug route via a PagesControler or a self-written NodesController.
My problem is that I would like to be able to mix and match url's with and without controllers, so actually what I want is that it checks if a :slug is part of the slug-list, there should still be the option to use that url with a controller.
I have created routes for both /en/contact and /en/:slugid, but it seems all queries were routed to my NodesController, even while I explicitly said that /en/contact should be routed to the ContactsController.
How can I instruct Cakephp to keep my current dictorary structure? I read the routes part of the Cakephp book, but it was extremely short and made me a little unsure about the possibility of such routing. If necessary, I'll just write a php-code that prints all routes for all slugs, so I can still write controller-routes with a similar path structure.
If a file exists in webroot (ie. app/webroot/static.html), the .htaccess file will tell Apache to serve that file before loading the CakePHP framework for requests to www.example.com/static.html.
Cake loads routes in a top-down order and will use the first matching route to handle a request. In your case, /en/contact should be above /en/:slugid, else the slugid rule will always win.
If CakePHP's routing does not accomplish what you are after, you can always implement a custom route class (book / example).

Resources