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
#2

[eluser]PowerCode[/eluser]
Ignore this.
#3

[eluser]therealmaloy[/eluser]
PowerCode,

why ignore him? justification?

he wants to learn!


modelreject

if you have autoloaded the models, ie. mproducts and mcats
you should also check the file names, it must be mproducts.php representing your MProducts class and so on..
file names and class names could make issues like this. Smile
#4

[eluser]Michael Wales[/eluser]
Code:
&lt;?php echo base_url(); ?&gt;
#5

[eluser]clintonbeattie[/eluser]
Thanks Michael.

I've added that into the MProducts Model and it works a treat.

Code:
"image" => base_url().$row['image']

I'll have to email Wrox and get them to add that to the errata.

Best.




Theme © iAndrew 2016 - Forum software by © MyBB