CodeIgniter Forums
How can I use a model function in the same model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How can I use a model function in the same model (/showthread.php?tid=60852)



How can I use a model function in the same model - El Forum - 07-13-2014

[eluser]Wathfea[/eluser]
Hi All!

I have a function which rerturn a value from the DB. How could I call this function in the same model?
Code:
<?php

class Admin_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

public function get_something($id) {
  //SQL bla bla . Request by id
  return $result;
}

public function something() {
get_something('2');   // I Think its not right
}



How can I use a model function in the same model - El Forum - 07-13-2014

[eluser]CroNiX[/eluser]
Code:
public function something() {
  $this->get_something('2');
  //or
  self::get_something(2);
}



How can I use a model function in the same model - El Forum - 07-13-2014

[eluser]Wathfea[/eluser]
Thx a lot working like a charm. Smile


How can I use a model function in the same model - El Forum - 07-15-2014

[eluser]www.sblog.in[/eluser]
when you are using the function from same class and if no other class will use that function then why don't you make that private

private function get_something($id) {
//SQL bla bla . Request by id
return $result;
}