views:

83

answers:

1

I recently downloaded cakephp-1.3.4. I set it up on my web server. I followed the advanced installation settings. My folder structure is as follows.

/common/
  cakephp/
     app/
     etc...
/htdoc/

The /htdoc folder is the webroot; cakephp resides in the common folder.

I have configured the paths in index.php to point to this folder structure. I have the app up and running. I created a layout, the app has picked it up (along with all the css and images - all that works).

I created a posts_controller.php in cakephp/app/controllers/. Now when I try to access the following page: http://localhost/posts. I get a message that the controller cannot be found and that I should create a app/controllers/posts_controller.php (it already exists!).

Also the strange thing is using the default pages_controller works. I created an about.ctp and dropped it in app/views/pages/about.ctp. Vising http://localhost/pages/about shows up as expected.

SOLUTION:

Sam helped me solve this problem (see the long comment thread below). The problem was I had set relative paths for my ROOT folder. This messed things up. The solution is to either directly set an absolute path or call realpath with your relative path for it to be resolved into the right absolute path.

+1  A: 

Make sure your controller class is named correctly (should be PostsController) and inherits from AppController (not strictly necessary but good practice).

Sam Day
@Sam: I copy pasted the code it shows on the Missing Controller page. So the name is PostsController and it does inherit from AppController
aip.cd.aish
What are you using for hosting? Are your file permissions ok?
Sam Day
@Sam: This is a shared hosting server. I did not modify the file permissions, other than what cakePHP asked me to in the initial set up (like setting the `tmp` folder as writable etc.)
aip.cd.aish
@aip.cd.aish: It just occurred to me that the pages_controller resides inside the core CakePHP installation. It sounds to me like CakePHP is having trouble accessing your /app directory at all. Double check you've configured it correctly and file permissions are ok.
Sam Day
@Sam: My layouts and view code which reside in the `app` folder got picked up correctly. Is there anything in specific I should check?
aip.cd.aish
@aip.cd.aish: More specifically, make sure your ROOT and APP_DIR is set correctly in webroot/index.php, as per documentation here: http://book.cakephp.org/view/915/Advanced-Installation
Sam Day
Also, you could try putting a snippet of code at the bottom of webroot/index.php (before $Dispatcher = new Dispatcher();) as follows: `pr(App::path("controllers"));`
Sam Day
+1 @Sam: That helped some. Doing the above, I saw 3 different paths. The first one is where the posts_controller resides. The second one was just the app/ folder itself. I tried moving the posts_controller there and that works. But I don't think that is the best solution. What do you think is wrong?
aip.cd.aish
@aip.cd.aish: Can you paste in the paths that are being shown?
Sam Day
@Sam: `[0]=>../common/cakephp-df6ffd4/app/controllers/[1]=>../common/cakephp-df6ffd4/app/[2]=>/f5/mysite/common/cakephp-df6ffd4/cake/libs/controller/`
aip.cd.aish
Okay your paths look a little messed up, make sure your ROOT is set to an absolute path, not a relative one. Use realpath() from webroot/index.php or something.
Sam Day
@Sam: You my friend are awesome! That was it, I passed the relative path to `realpath` and set that as the new path and it worked beautifully. I was the one who set the relative paths. Thanks! :)
aip.cd.aish
@aip.cd.aish: Glad I could help :)
Sam Day