CodeIgniter Forums
Model Functions - Same Code - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Model Functions - Same Code (/thread-9397.html)



Model Functions - Same Code - El Forum - 06-24-2008

[eluser]Yash[/eluser]
Code:
class Usersmodel extends Model {

    function Usersmodel()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function Abc()
    {
    //some code is here
    }
        
        function 123()
       {//I want to use here

        }

        function TBG()
       {//I want to use and here

        }

}

How can we do this?


Model Functions - Same Code - El Forum - 06-24-2008

[eluser]Yash[/eluser]
Suppose I need to generate random numbers and I want to use this code in each model function how I can do this.

writing code again and again is not a good idea

any ideas?

sorry for bump


Model Functions - Same Code - El Forum - 06-24-2008

[eluser]Sam Dark[/eluser]
MY_Model.php
Code:
<?php
class BaseModel extends Model {
    function __construct(){
        parent::__construct();
    }

        //Your code here
}
?>

Code:
class Post extends BaseModel {
   //Your code here
}



Model Functions - Same Code - El Forum - 06-24-2008

[eluser]Sam Dark[/eluser]
Also you can use helper / library / plugin for this purpose.


Model Functions - Same Code - El Forum - 06-24-2008

[eluser]Yash[/eluser]
Nope..I want to use different functions in same model..and don't want to use $this I mean don't want to load that model itself.


Model Functions - Same Code - El Forum - 06-24-2008

[eluser]Sam Dark[/eluser]
Code:
class Post extends Model {
  ststic function doit(){
    return '123';
  }
  
  function get_123(){
    return self::doit();
  }
}



Model Functions - Same Code - El Forum - 06-24-2008

[eluser]Yash[/eluser]
SuperBBB..thank you man
it works like a magic