/    Sign up×
Community /Pin to ProfileBookmark

CakePHP giving me missing action message

Hi all,

I’m trying to define the following action “validate” for the controller “ProjectsController” but for some reason cake is throwing a wobbly.

[code=php]
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.”);
}
}
}
[/code]

Even if I make the action completely empty:

[code=php]
function validate() {

}
[/code]

Cake is still giving me:

[code=html]
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() {

}

}
?>
[/code]

Does anyone have any idea why this is?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiApr 04.2010 — Probably to do with the fact you are extending your controller from AppModel instead of AppController :p

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.
Copy linkTweet thisAlerts:
@blue-eye-labsauthorApr 04.2010 — Sorry, that was a typo, it wasn't copied directly. I'll change it.

Thanks for the tip.

So any ideas why it isn't working?
Copy linkTweet thisAlerts:
@MindzaiApr 04.2010 — 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:

[code=php]
Router::connect('/projects/validate/*', array('controller' => 'projects', 'action' => 'renamed_validate_action'));
[/code]
Copy linkTweet thisAlerts:
@blue-eye-labsauthorApr 04.2010 — 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:

[code=php]
Router::connect('/projects/validate/*', array('controller' => 'projects', 'action' => 'renamed_validate_action'));
[/code]
[/QUOTE]


Okay, brilliant. Thanks.
×

Success!

Help @blue-eye-labs spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...