0

I have controller class EmployeeController in employee_controller.php file,and i have a model class Employee in employee.php ,database table is employees ,All the functions are working (such as findall() and read() are working fine),but i have add function which is like this

    function add() {
        if (!empty($this->data)) {
        if ($this->Employee->save($this->data)) {
        $this->Session->setFlash('Employee has been saved.');
        $this->redirect(array('action' => 'index'));
            }

When i tried to save ,An error EmployeesController not found will display and shows the following code

<?php
class EmployeesController extends AppController {
    var $name = 'Employees';
}
?>

i am not able to solve this problem ,please help me out to get rid of this problem

1
  • Usually, reading the error message will give you a BIG clue to what is wrong.
    – Leo
    Feb 15, 2011 at 9:24

3 Answers 3

7

The file should be called employees_controller.php, not employee_controller.php.

All controller files are named in the plural.

1
  • While this is CakePHP convention, and as such you're probably better off following it, CakePHP doesn't actually force you to use plural words to name your controllers. As long as the file name, the class name, and the $name attribute of your controller all match, then it could very well be employee_controller.php, class EmployeeController, and public $name = "Employee" May 8, 2012 at 17:19
0

You can also learn about the naming of the tables and the conventions at http://cakeapp.com

0

I don't know if the question is still important, but the cakephp convention says that filenames for controllers must be in plural an without underscores, so your controller file should be named EmployeesController.php.

1
  • you do realize that this was back in the 1.3 days, don't you? :)
    – mark
    Dec 28, 2012 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.