CodeIgniter Forums
Blank page after loading model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Blank page after loading model (/showthread.php?tid=12244)



Blank page after loading model - El Forum - 10-11-2008

[eluser]Zac G.[/eluser]
I just added a model to autoload and now I am getting a blank page. Any ideas about why this would happen? The same thing happens if I load the model manually.


Blank page after loading model - El Forum - 10-11-2008

[eluser]ray73864[/eluser]
mind pasting the code for the model? hard to diagnose the problem without it


Blank page after loading model - El Forum - 10-11-2008

[eluser]Zac G.[/eluser]
Sure!

I am working through the Wrox CI book, and this is my model:

The file name is mproducts.php

Code:
<?php
class MProducts extends Model
{
    function MProducts()
    {
        parent::Model();
    }
    
    function getProduct($id)
    {
        $data = array();
        $options = array(
            'id' => id_clean($id)
        );
        
        $Q = $this->db->getwhere(
            'products',$options,1
        );
        
        if ($Q->num_rows() > 0)
        {
          $data = $Q->row_array();
        }

        $Q->free_result();    
        return $data;      
    }
    
    function getAllProducts()
    {
        $data = array();
        $Q = $this->db->get('products');
        if ($Q->num_rows() > 0)
        {
               foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
               }
        }

        $Q->free_result();    
        return $data;
    }

    function getProductsByCategory($category_id)
    {
        $data = array();
        $this->db->select('id,name,shortdesc,thumbnail');
        $this->db->where('category_id', id_clean($catid));
        $this->db->where('status', 'active');
        $this->db->orderby('name','asc');
        $Q = $this->db->get('products');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row)
            {
                $data[] = $row;
            }
        }

        $Q->free_result();    
        return $data;    
    }
    
    function getMainFeature()
    {
         $data = array();
         $this->db->select("id,name,shortdesc,image");
         $this->db->where('featured','true');
         $this->db->where('status', 'active');
         $this->db->orderby("rand()");
         $this->db->limit(1);
         $Q = $this->db->get('products');
         if ($Q->num_rows() > 0)
         {
             foreach ($Q->result_array() as $row)
            {
                $data = array(
                 "id" => $row['id'],
                 "name" => $row['name'],
                 "shortdesc" => $row['shortdesc'],
                 "image" => $row['image']
                 );
           }
        }
    
        $Q->free_result();    
        return $data;  
    }
    
    function getRandomProducts($limit, $skip)
    {
        $data = array();
        $temp = array();
        if ($limit == 0)
        {
            $limit=3;
        }
        $this->db->select("id,name,thumbnail,category_id");
        $this->db->where('id !=', id_clean($skip));
        $this->db->orderby("category_id","asc");
        $this->db->limit(100);
        $Q = $this->db->get('products');
        if ($Q->num_rows() > 0)
        {
            foreach ($Q->result_array() as $row){
             $temp[$row['category_id']] = array(
                 "id" => $row['id'],
                 "name" => $row['name'],
                 "thumbnail" => $row['thumbnail']
                 );
            }
        }

        shuffle($temp);
        if (count($temp))
        {
            for ($i=1;$i<=$limit; $i++)
            {
                $data[] = array_shift($temp);
            }
        }
        
        $Q->free_result();    
        return $data;
    }
}
?&gt;



Blank page after loading model - El Forum - 10-11-2008

[eluser]Zac G.[/eluser]
I have no idea what the problem was, but I seem to have fixed it. I think that something wasn't being passed right to one of the functions.


Blank page after loading model - El Forum - 10-12-2008

[eluser]Jamie Rumbelow[/eluser]
You usually get blank screens when php errors is turned off and you get a syntax error. Next time it happens, do a syntax check.


Blank page after loading model - El Forum - 10-12-2008

[eluser]Zac G.[/eluser]
Ah yes, it was blank because errors were turned off. Thanks!