如何从 Kohana 3 中的同一控制器从另一个方法调用一个方法

How to call one method from another method from the same controller in Kohana 3

我有两个方法,我想在第一个方法中调用另一个方法。他们在同一个控制器中。我以这种方式尝试过,但出现错误:

Call to undefined method Controller_User::getUser()

我的控制器看起来像这样:

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_User extends Controller {

   public function action_index (){
       $id = $this->request->param('id');
       $user = self::getUser($id);
  }

 public function action_getUser ($id){
      //some code here
  }


}

这两个函数都在相同的 class 中,因此在您的情况下使用 $this-> 调用相同 class 中的其他方法,就像评论用户 $this->action_getUser 中提到的 kingkero ($id)