Assignment
Assignment
<?php
class Products_model extends CI_Model{
public function __construct(){
parent::__construct();
$this->load->database();
}
Products(Controller)
<?php
class Products extends CI_Controller{
public function __construct(){
parent::__construct();
$this->load->model('Products_model');
}
$this->load->view('pages/products', $data);
}
if (empty($data['product'])){
show_404();
}
$data['title'] = $data['product']['name'];
$this->load->view('pages/product', $data);
}
}
?>
products(View)
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<table>
<thead>
<tr>
<th>Product_ID</th>
<th>Name</th>
<th>Description</th>
<th>Price</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach($tblproducts as $product): ?>
<tr>
<td><?php echo $product["product_id"]; ?></td>
<td><?php echo $product["name"]; ?></td>
<td><?php echo $product["description"]; ?></td>
<td><?php echo $product["price"]; ?></td>
<td><a href="<?php echo base_url('products/view/' .
$product['product_id']); ?>">View</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
product(View)
<!DOCTYPE html>
<html>
<head>
<title><?php echo $title; ?></title>
</head>
<body>
<h1><?php echo $title; ?></h1>
<strong>ID</strong>: <?php echo $product['product_id']; ?> <br />
<strong>Name</strong>: <?php echo $product['name']; ?> <br />
<strong>Description</strong>: <?php echo $product['description']; ?> <br />
<strong>Price</strong>: <?php echo $product['price']; ?> <br />
<td><a href="<?php echo base_url('products/'); ?>">Back</a></td>
</body>
</html>