@brandy
To get value from another model in CodeIgniter, you can follow these steps:
1
|
$this->load->model('Model_name'); |
1
|
$value = $this->Model_name->method_name(); |
Here is an example:
Controller:
1 2 3 4 |
$this->load->model('User_model'); $user_name = $this->User_model->get_user_name(); $data['user_name'] = $user_name; $this->load->view('view_name', $data); |
Model:
1 2 3 4 |
public function get_user_name() { $user = $this->db->get('users')->row(); return $user->name; } |
View:
1
|
<h1>Welcome, <?php echo $user_name; ?></h1> |
This is how you can get a value from another model in CodeIgniter.