0
votes

i installed fresh cakephp. its app controller working fine. but when i write my controller and its view but this result in page not found. My code is given below

class PostsController extends Controller {
    public $helpers = array('Html', 'Form');
    public function index() {
        $this->set('posts', $this->Post->find('all'));
    }
}

and create folder named Posts in view folder and over there create index.ctp file as well. but its result in page not found. Please help what may be mistake by me or is there any need to configuration. Thanks

2
The code looks fine. Which CakePHP version do you use? What is the filename of your controller? And how do you try to access your controller?dhofstet
version 2.4.6 filename PostController.php www.example.com/Post/indexMuhammad Ali Hassan
You should be navigating to posts with an s, as in www.example.com/posts/index (the capitalization doesn't matter on "posts" or "index")Kai
i tried both posts and Posts but same resultMuhammad Ali Hassan
The file has to be named PostsController.php and you have to access it in the way @Kai mentioned.dhofstet

2 Answers

3
votes

Your controller should be named PostsController.php (ie plural)

Just spotted it, you need to extend AppController in CakePHP 2.x, not Controller: ie:

class PostsController extends AppController {
0
votes

there might problem apache rewrite module. if you are using WAMP, just put on your rewrite module.