Articles → PHP CODEIGNITER → Views In Codeigniter

Views In Codeigniter






Purpose





Example




<?php
class mymodel extends CI_Model {
public function GetUsers()
{
return array("Volvo", "BMW", "Toyota");
}
}




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

class users_list extends CI_Controller {
public function Index()
{
$this->load->model('mymodel', 'mm');
$data['users'] = $this->mm->GetUsers();

$this->load->view('users', $data);
}
}




<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?><!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>

<div id="container">
<h1>User List</h1>

<div id="body">
<ul>
    <?php foreach($users as $user ): ?>
<li>
<?= $user ?> 
</li>
<?php endforeach ?>
</ul>
</div>

</body>
</html>



Output


Picture showing the output of views in codeigniter
Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, July 14, 2020

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250