CodeIgniter Forums

Full Version: Model Functions - Same Code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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

El Forum

[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

El Forum

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

El Forum

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

El Forum

[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.

El Forum

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

El Forum

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