Skip to content

6.2 Registering Model

Taufik Firmansyah edited this page Jul 15, 2015 · 2 revisions

Sometime you need to create model for used a cross controller and view . Ofcourse , you can use more than one table inside model

Model

<?php
class Mymodel extends SB_Model{


}
Method / Function
<?php
class Mymodel extends SB_Model{

    static function myFirstFunction()
    {
        return 'hai this is my first function';
    }

}
Calling your method/function

Once method/funtion created inside class model , this will available a cross controller and views

Controller

Calling your model function inside controller

$this->load->model('Mymodel');
$this->model = $this->Mymodel;
$row = $this->model->myFirstFunction;

//this will return 

'hai this is my first function'

View

Calling your model function inside controller

<?php echo $this->model->myFirstFunction() ?>

//this will return 

'hai this is my first function'

Clone this wiki locally