cakephp add new controller path - cakephp

Background: I'm new to CakePHP and trying to modify an preexisting project.
When I try to add a new UploadsController it is supposed to handle xxxx/uploads requests right?
However, when entering the url neither AppController or UploadsController, allow index.php to do a dispatch. Files are being called. It goes straight to /uploads which is a directory.
I realize this is a bad design to begin with but trying to fix things one step at a time. Need to authenticate before going to /uploads, and than take action.
What am I doing wrong? I tried to modify routes.php to specify controller but that does not work either.

So as I said I am new and fixing someone else's project. I found that there is a security issue where uploads directory is exposed. So I figured I would add Controller to take care of this. uploads folder was under webroot as a result it was going to uploads folder and was not directing to controller. Thanks and hopes this helps someone in the future.. although kind of doubt it since it was a really bad way to do this to begin with.

With the info you gave this is what I can suggest:
Check to see if the UploadsController is in the Controller folder.
Make sure that there's at least a index.ctp file in Views/Uploads/
Check to see if the UploadsController has a default index() method. This is what www.example.com/uploads/ will hit.

Related

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 ?

How to find current controller or action in routes.php in cakephp

I try lots of methods to find current controller and action in cakephp routing, but I didn't got answer. Is there any method to find controller and action in routing. If yes, please help me. Or if there is any other way to find these, Please tell me.
It's the routes that decide to what controller and action a url maps to. When routes.php is being loaded the routing process has still not been done (since you are still setting up routes), so you cannot know controller or action is in routes.php.
If the website formatted something like this :
www.johndoe.test/test/test_action/
then probably it can be found on test controller but of course that depends on the settings of the website on how the developer configured it. It may also be found on routes.php like #ADmad said.

CakePHP Display Error

My last post can be found here,
CakePHP Issue : Call to a member function find() on a non-object
I am asking a new question, as the people who answered my last question, said that the error I am getting now is a new problem, therefore a new post.
Please read my last post, if any of you wish me to re-post all my code on this post I will do so, just ask!
So my problem is that, yes once I do remove the vars $uses from my code, it works in the NEW copy of cake I have put on the same server. However it just bypasses my die command when I use it on my live site! Now I know (or at lest think) this must be something to do with the way this copy of cake was configured.
Also, in the NEW copy of cake I did not have to add a 'Router' path in the routes.php file for it to work. However on the live site, it will just give me a 404 error when trying to access the controller. Now with the NEW copy of cake, I called the function index(), but in the live site I named it eventDetails(), now I have tried changing this to index(), but I still get a 404 error when the router path is not there and the same 'Internal Error Has Occurred', see last post.
Any ideas?
Again any help would be very welcome.
Glenn Curtis.
Thanks For your help Dunhamzz.
But I have solved the issue. I knew it was something to do with my set-up and the guy who set-up this cake site set the debug level to 0. While the new copy of cake had it set to 2.
Thanks
Glenn.

cakephp alias url

The url structure of my cakephp based site is mysite/cakephp/myapp/index.php/controller/action/input_paramaters
I cannot remove index.php from my url, as I dont have access to httpd.conf file.
Anyways, my question is that I just need to change the url of my homepage to something like http://mysite or mysite/myapp
How would I do that?
Thanks a lot!!
The problem sounds to me that you don't have mod_rewrite enabled or Apache AllowOverwrite is not set properly.
If you don't have mod_rewrite then you cannot change the urls with the pretty ones (provided from CakePHP).
If the AllowOverwrite is not set to On. Then even if you have mod_rewrite enabled, the .htaccess files in your directories doesn't take effect.
I don't know which is worst. Speak with your hosting provider and ask for help.
It is not really clear to me which part of the URL changes. CakePHP routing applies only relative from the cake directory. So if you move from http://example.com/foo to http://www.example.org/bar nothing needs to be changed in Cake.
However you might have hardcoded some img/CSS/JS URL-s that needs some work now. I also use the HTML base tag so my app works perfectly fine under various base URL-s.

Can not get session in cakePHP

I have problem with session in cakephp.I have one file chat.php that is in webroot folder but when I run that file with ajax I could not find session which is created from chat.ctp file.
so anyone has idea how to get session in third party file in cakePHP.
can I write session any .ctp file ?
Thanks.please help me.
Yes, it's totally possible.
In APP/config/core.php, find the "Session.cookie" config value:
Configure::write('Session.cookie', 'CAKEPHP');
Then, in your external file, just set the same session name when you start your session:
session_name('CAKEPHP');
session_start();
print_r($_SESSION);
I have heard that this is a spotty thing but for me, the solution above has worked in two projects so far.
I'm assuming you're using the Session component to write the session variable and then trying to read it from a regular 'ol php file outside of cake's scope using the $_SESSION variable.
As you have figure out, this is not guaranteed to work properly. The best way to handle this would be to integrate your chat.php file into cake, using a controller, action and view.
If this for some strange reason isn't possible, you would need to import all the files responsible for setting up cake and instantiate the session component and use that to read from your session. I'd strongly recommend going with way #1.
I don't think it's a good idea to use the third party session in CakePHP since Cake has already done that very well.And I believe the best place to make some sessions is controller,not view.See Session in Cakephp's cookbook and Ajax helper of Cake.Probably they would help.

Resources