views:

49

answers:

4

(I'm really hoping I put in enough due dilligence on google and the search bar before posting this)

I'm getting started with CakePHP and just created my first model, controller, and view.

When I browse to http://localhost/~me/MyApp/Lists I get a 404 and I'm not sure why

Here's my controller

<?php
    class ListsController extends AppController 
    {    
        var $name = 'Lists';

        function index()
        {
            $this->set('lists', $this->List->find('all'));
        }
    }
?>

I would think it's a .htaccess issue but when I browse to http://localhost/~me/MyApp/app or http://localhost/~me/MyApp/index I get a "Missing Controller" error page. Granted both of these URLs would otherwise point at an actual file or directory.

Can anyone tell me why I would be getting this 404 on my controllers?

Update for a couple comments left below (see the answer by Leo)

My .htacces for the application root

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

My .htaccess for the CakePHP webroot

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
A: 

Your url should be http://localhost/~me/MyApp/lists with 'lists' lowercased. And url http://localhost/~me/MyApp/app and http://localhost/~me/MyApp/index would get you missing controller page because if you use .htaccess, all request will be handled by app/webroot/index.php.

Jamal Aziz
Tried that, I'm acctually getting 404s in for anything past http://localhost/~me/MyApp/
Antilogic
I should also note that the url http://localhost/~me/MyApp/lists goes to a 404 that reads "The requested URL /Users/adam/Sites/Pluralist/app/webroot/lists was not found on this server." (note the ".../app/webroot/..." part). So the root directory .htaccess file seems to be working
Antilogic
+1  A: 

I think the problem is in the /~me/. Try to move your project at least on: http://localhost/MyApp

I remember that we had such problem long time ago. It's possible to fix it, but for sure you wont leave the site with such url in the production server, so just change the url :)

Nik
A: 

Looks to me like you don't have mod_rewrite working properly. Create a phpinfo.php file containing only the following:

<?php echo phpinfo() ?>

Put it in webroot then access it as http://localhost/~me/MyApp/phpinfo.php

In the browser do ctrl-f and search for 'rewrite'. If it's not there, it's not set up.

Leo
It's listed under the "Loaded Modules" section in the "apache2handler" block. I'm assuming though you're saying mod_rewrite should have it's own block in phpinfo(), which it doesn't.
Antilogic
It is correct and loaded if it appears in the apache2handler block. It shouldn't appear anywhere else. What does your .htaccess look like? (The one in the website root - i.e. the same level as the app folder)
Leo
I've added my .htaccess files above. I'm terrible with regex but It looks like the root .htaccess forwards the request on to "/app/webroot" and then the webroot .htaccess parses apart the url and forwards on to index.php as url parameters. Note: when I disable my mod_rewrite and access index.php?url=lists the app works fine. So it looks like I'm dealing exclusively with a routing issue
Antilogic
I think it had something to do with the <Directory> configuration settings. I set AllowOverrides to All for the /Library/WebServer/Documents (OSX) Directory listing and moved the app over there and it works now. I'm not sure what exactly got it to work but I'm going to play around and see if I can mod_rewrite to work in my User's Sites folder
Antilogic
Your .htaccess files look fine - they're out-of-the-box CakePHP. Regarding the AllowOverrides setting, you might find this link useful, although I wrote it for Ubuntu: http://leoponton.blogspot.com/2010/05/getting-cakephp-up-and-running-on.html Glad to know you've got it working.
Leo
A: 

Look at app/webroot/index.php and make sure the root, app, and core paths are defined correctly.

Another thing to try (although I doubt this is your problem) is to add RewriteBase /~me to all your htaccess files (there is one in the root directory of your site, one in the app directory, and one in the webroot directory).

handsofaten