开发者

cakephp Additional method in Model causes 500 Error

开发者 https://www.devze.com 2023-02-25 15:28 出处:网络
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 p

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开发者_Go百科) {
 $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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消