In this example, we will show how to pass multiple data from controller to model in Codeigniter. We will show Codeigniter pass multiple data from controller to model. You will learn how to pass multiple parameters from the controller to the model in Codeigniter.


After reading this post you can simply pass multiple data from controller to model. I will provide an example of pass multiple data from controller to model in Codeigniter. We will show pass data or parameters from the controller to the model using Codeigniter.


Create Controller

Create DemoController  controller file 

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class DemoController extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('demo');
        $this->now_time = date('Y-m-d H:i:s');
    }
    
    function get_all_data(){
        $demo = $this->demo->get_all_records('demo','created_at','desc');
        echo "<pre>";
        print_r($demo);exit;
    }
}

Create Model

Create Demo model file 

<?php

class Demo extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function get_all_records($table_name,$order_by_column,$order_by_value){
        $this->db->select("*");
        $this->db->from($table_name);
        $this->db->order_by($order_by_column,$order_by_value);
        $query = $this->db->get();
        if ($query->num_rows() > 0){
            return $query->result();
        }else{
            return false;
        }
    }
    
}

Thanks may this example help you.....