How to Pass Multiple Data from Controller to Model in CodeIgniter

How to Pass Multiple Data from Controller to Model in CodeIgniter

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 controller to model in codeigniter.

After read this post you can simple pass multiple data from controller to model. I will provide example of pass multiple data from controller to model in codeigniter. We will show pass data or parameters from controller to model using codeigniter.

Read Also :  PayPal Integration in Laravel Example

Example : Pass multiple data from controller to model using codeigniter

Create Controller

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

<?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;
        }
    }
    
}

I hope you understand of codeigniter pass multiple data from controller to model and it can help you..

Read Also :  PHP Array Functions With Examples