I'm trying to define the following action "validate" for the controller "ProjectsController" but for some reason cake is throwing a wobbly.
PHP Code:
class ProjectsController extends AppController { var $name = "Projects";
//... some other actions which all work
function validate($what) { $this->layout = "ajax";
switch($what) { case "title": $count = $this->Project->find("count", array("conditions"=>array("title"=>$this->data["data"]))); $this->set("isValid", ( ($count == 0) ? true : false )); $this->set("message", ( ($count == 0) ? "" : "A project with this title already exists." )); break; default: $this->set("isValid", false); $this->set("message", "No validation rules exist for $what."); } } }
Even if I make the action completely empty:
PHP Code:
function validate() {
}
Cake is still giving me:
HTML Code:
Missing Method in ProjectsController
Error: The action validate is not defined in controller ProjectsController
Error: Create ProjectsController::validate() in file: app/controllers/projects_controller.php.
<?php
class ProjectsController extends AppController {
var $name = 'Projects';
function validate() {
}
}
?>
Does anyone have any idea why this is?
Last edited by blue-eye-labs; 04-04-2010 at 07:35 AM.
Reason: appcontroller not model
Probably to do with the fact you are extending your controller from AppModel instead of AppController
BTW just a general tip, if you use the RequestHandler component, Cake will automatically render your ajax views within your ajax layout when it detects an ajax request, so you don't need to modify your action in any way. If you configure the router to parse extensions you can extend this further still - for instance I typically have RequestHandler parse .json and .rss extensions - that way I use the exact same controller/action code, but depending on the request type and extension cake automatically renders either /controller/view.ctp, /controller/ajax/view.ctp, /controller/json/view.ctp or /controller/rss/view.ctp - and it also loads their corresponding layout, eg /layouts/ajax/default.ctp.
The first rule of Tautology Club is the first rule of Tautology Club.
Controller already has a method named validate, and your AppController extends Controller, and this controller in turn extends AppController. You will need to change the name of the action. If you want to still use /projects/validate as a URL, add the following to app/config/routes.php:
Controller already has a method named validate, and your AppController extends Controller, and this controller in turn extends AppController. You will need to change the name of the action. If you want to still use /projects/validate as a URL, add the following to app/config/routes.php:
Bookmarks