0

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

7
  • 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? Commented Mar 7, 2014 at 16:26
  • version 2.4.6 filename PostController.php www.example.com/Post/index Commented Mar 7, 2014 at 16:29
  • 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") Commented Mar 7, 2014 at 16:32
  • i tried both posts and Posts but same result Commented Mar 7, 2014 at 16:40
  • The file has to be named PostsController.php and you have to access it in the way @Kai mentioned. Commented Mar 7, 2014 at 16:44

2 Answers 2

3

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 {
Sign up to request clarification or add additional context in comments.

4 Comments

change controller PostsController.php but same result
See edit to answer above re: extending App Controller
sorry changes to AppController. but same. is there any need to configure somewhere for routing?
Is it a 1.3 application which you're upgrading to 2.4?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.