Taff
Taff

Reputation: 231

cakephp Additional method in Model causes 500 Error

Hey, I am trying to optimise a couple of cakephp controllers with some additional methods in the model but am getting a 500 Internal Server error returned. Can anyone point me in the right direction please?

Model:

function getID($id) {
 $tmp = $this->find("all",array('conditions'=>array('Model.id'=>$id)));
 return $tmp;
}

Controller:

function getTotalQuestions(){
 $tmp=$this->Model->getID(7);
 debug($tmp);
}

Occasionally I don't get a 500 error, but an error message telling me no variable has been passed to getID.

Any help would be greatly appreciated Taff

Upvotes: 0

Views: 303

Answers (1)

Chuck Burgess
Chuck Burgess

Reputation: 11574

It is how you are wording your functions (most likely). You need to change the format of the function names:

function get_id($id = null) {
   // code here
}

function get_total_questions() {
   $tmp = $this->Model->get_id(7);
  // ...
}

Take a look at http://book.cakephp.org/view/908/Requirements#!/view/904/Controller-Conventions for more details. But it states:

the convention is that your urls are lowercase and underscored, therefore /red_apples/go_pick is the correct form to access the RedApplesController::go_pick action.

Upvotes: 1

Related Questions