Welcome Guest, Not a member yet? Register   Sign In
Wrox book error frustrating. Please help.
#1

[eluser]clintonbeattie[/eluser]
Resolved this. I used a lowercase letter when autoloading my models.


One other strange thing is that images aren't visible because the base url isn't attached to them. I have 'images/image.jpg' instead of 'http://localhost/codeigniter/images/image.jpg'.

Any thoughts?





Hi,

Anyone else is using the Wrox codeigniter book?

I have this error being thrown on my welcome page.

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$MProducts

Filename: controllers/welcome.php

Line Number: 13

Fatal error: Call to a member function getMainFeature() on a non-object in C:\xampp\htdocs\codeigniter\system\application\controllers\welcome.php on line 13

I have reached page 108. This is my code for the welcome controller...

Code:
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index(){
        $data['title'] = "Welcome to Claudia's Kids";
        $data['navlist'] = $this->MCats->getCategoriesNav();
        $data['mainf'] = $this-> MProducts->getMainFeature();
        $skip = $data['mainf']['id'];
        $data['sidef'] = $this->MProducts->getRandomProducts(3,$skip);
        $data['main'] = 'home';
        $this->load->vars($data);
        $this->load->view('template');
    }
}

I'm definitely no expert but all this seems to be fine.
This is my mproduct.php file...

Code:
class MProducts extends Model {
    function MProducts() {
        parent::Model();
    }
    
    function getProduct($id) {
        $data = array();
        $options = array('id' => $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 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;  
    }
    
    
}


I would grateful if someone could shed some light on this as it's driving me crazy.

Thanks,
Clinton


Messages In This Thread
Wrox book error frustrating. Please help. - by El Forum - 12-31-2008, 07:36 AM
Wrox book error frustrating. Please help. - by El Forum - 12-31-2008, 09:04 AM
Wrox book error frustrating. Please help. - by El Forum - 12-31-2008, 04:47 PM
Wrox book error frustrating. Please help. - by El Forum - 12-31-2008, 10:53 PM
Wrox book error frustrating. Please help. - by El Forum - 01-01-2009, 09:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB