• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Blank Controller page when loading view

#1
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
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();
    }

}
 CONTROLLER
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>";
    }

}
VIEW
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?
Reply

#2
Hi,

You have:
PHP Code:
$this->load->view('pro_index'$dataTRUE); 

The 'TRUE' is returning the view as a string, not outputting it to the browser. Just use:

PHP Code:
$this->load->view('pro_index'$data); 

http://www.codeigniter.com/user_guide/ge...ing-a-view

Hope that helps,

Paul.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.