• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Model Functions - Same Code

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

#2
[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

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

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

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

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

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.