06-30-2016, 08:12 PM
Hi, am new to codeigniter and encountered this case while learning. When i try to load the view, my page is blank and no error is displayed even though i have error reporting set to on. I'm using WAMP with PHP version 5.5.12, MYSQL 5.6.17, Apache 2.4.9 and the code am learning with is
MODEL
CONTROLLER
VIEW
What is it am doing wrong?
MODEL
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Product extends CI_Model {
function get_products() {
$this->db->select()->from('products')->order_by('name','desc');
$query=$this->db->get();
return $query->result_array();
}
}
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Products extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->model('product');
$data['products']=$this->product->get_products();
$this->load->view('pro_index', $data, TRUE);
//echo "<pre>"; print_r($data['products']); "</pre>";
}
}
Code:
<!DOCTYPE html>
<html lang="">
<head>
<!-- Required meta tags always come first -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Title Page</title>
</head>
<body>
<?php
if (isset($products)) {
foreach ($products as $row) {
echo "<div>"."<h2>".$row["name"]."</h2>"."</div>";
echo "what is this?";
}
}
print_r($products);
?>
</body>
</html>
What is it am doing wrong?