How to send data from controller to view in CodeIgniter?

Asked  Jul 25, 12:35 am 40 Views Add Your Answer
Asked  Jul 25, 12:35 am

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

class Controller_name extends CI_Controller {
	
   public function index()
   {
       // data how
       $this->load->view('file_name');
    }

}

0 Dislikes
0 Comments

1 Answers

Added  Jul 25, 12:38 am

Send data from controller to view

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

class Controller_name extends CI_Controller {
	
   public function index()
   {
       // send data
       $data['var_name'] = 'This is variable value';
       $this->load->view('file_name', $data);
    }

}

get data in view file

<?php
// $data['var_name'] = 'This is variable value';

echo $var_name;
// This is variable value
?>

0 Likes 0 Dislikes
0 Comments
×
Google login
SignUp with Email
X