Search code examples
methodscontrollerkohana

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


I have two methods and I want in first method to call the other method. They are in the same controller. I tried in this way but I'm getting error:

Call to undefined method Controller_User::getUser()

My controller looks like that:

<?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
  }


}

Solution

  • Both functions are in same class so use $this-> to call other method in same class in your case as kingkero mentioned in comment user $this->action_getUser($id)