views:

46

answers:

1

I suffered a CakePHP Route Problem. I can only access the root "/" and it shows the CakePHP default welcome home page. Later I try to write my controller (icons_controller.php) and views (views/icons/index.ctp), it has problem. I typed in http://localhost:8080/myapp/icons/ It always says "Not Found The requested URL /myapp/icons/ was not found on this server." In my routers.php file it has:

Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

I create a controller in the icons_controller.php file like:

<?php
class IconsController extends AppController{
 var $name = 'Icons'; 
 function index() {
  $this->set('icons', $this->Icon->find('all'));
 }
}
?>

And it should simple open the file with only a paragraph tag text (in /views/icons/index.ctp)

<h1>My Icons</h1>

But I cannot open the index.ctp by using localhost:8080/myapp/icons/. So later I tried to modify my routers.php file like this, it works fine with the url http://localhost:8080/myapp/:

Router::connect('/', array('controller' => 'icons', 'action' => 'index'));
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

It is fine and success display the "My Icons" text. Wondering why only works under "/", with anything else doesn't work.

+1  A: 

Check to make sure that you have mod_rewrite enabled on Apache.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Matt Huggins
See also: http://book.cakephp.org/view/917/Apache-and-mod_rewrite-and-htaccess and http://book.cakephp.org/view/1533/A-Note-on-mod_rewrite
deizel