Welcome Guest, Not a member yet? Register   Sign In
"Claudia's Kids" wrox shopping tutorial: function updateCart() on a non-object
#1

[eluser]antoniog[/eluser]
I'm doing the tutorial from the book "Professional CodeIgniter" published by Wrox.
At this point in the tutorial, click on "add to cart" above the image should appear to me the two following pieces of code, the first enclosed in a box with a red edge.

First part of code (in the box):
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Welcome::$MOrders

Filename: controllers/welcome.php

Line Number: 88

Second part of code:
Code:
Fatal error: Call to a member function updateCart() on a non-object in /home/youngtea/public_html/igniter/application/controllers/welcome.php on line 88

Code of welcome.php (the controller)
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

/**
  * Index Page for this controller.
  *
  * Maps to the following URL
  *   http://example.com/index.php/welcome
  * - or -  
  *   http://example.com/index.php/welcome/index
  * - or -
  * Since this controller is set as the default controller in
  * config/routes.php, it's displayed at http://example.com/
  *
  * So any other public methods not prefixed with an underscore will
  * map to /index.php/welcome/<method_name>
  * @see http://ellislab.com/codeigniter/user-guide/general/urls.html
  *
  */

  function __construct()
  {
        // Call the Model constructor
        parent::__construct();
        $this->load->library('session');
        $this->load->library('cart');
  }

public 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');
}

  public function cat($id)
  {
  $cat = $this->MCats->getCategory($id);
    if (!count($cat))
    {
      redirect('welcome/index','refresh');
    }
    $data['title'] = "Claudia's Kids | ".$cat['name'];
    if ($cat['parentid'] < 1)
    {
      $data['listing'] = $this->MCats->getSubCategories($id);
      $data['level'] = 1;
    }
    else
    {
      $data['listing'] = $this->MProducts->getProductsByCategory($id);
      $data['level'] = 2;
    }
    $data['category'] = $cat;
    $data['main'] = 'category';
    $data['navlist'] = $this->MCats->getCategoriesNav();
   $this->load->vars($data);
    $this->load->view('template');
}

  public function product($id)
  {
    $product = $this->MProducts->getProduct($id);
    if (!count($product))
    {
      redirect('welcome/index','refresh');
    }
    $data['grouplist'] = $this->MProducts->getProductsByGroup(3,$product['grouping'],$id);
    $data['product'] = $product;
    $data['title'] = "Claudia's Kids | ".$product['name'];
    $data['main'] = 'product';
    $data['navlist'] = $this->MCats->getCategoriesNav();
    $this->load->vars($data);
    $this->load->view('template');
}

  public function cart($productid=0)
{
    if ($productid > 0)
    {
      $fullproduct = $this->MProducts->getProduct($productid);
      $this->MOrders->updateCart($productid,$fullproduct);
      redirect('welcome/product/'.$productid, 'refresh');
    }
    else
    {
      $data['title'] = "Claudia's Kids | Shopping Cart";
      if (count($_SESSION['cart']) == true)
      {
        $data['main'] = 'shoppingcart';
        $data['navlist'] = $this->MCats->getCategoriesNav();
        $this->load->vars($data);
        $this->load->view('template');
      }
      else
      {
        redirect('welcome/index', 'refresh');
      }
    }
}

  public function search()
  {
  if ($this->input->post('term'))
    {
      $data['results'] = $this->MProducts->search($this->input->post('term'));
    }
    else
    {
      redirect('welcome/index','refresh');
    }
    $data['main'] = 'search';
    $data['title'] = "Claudia's Kids | Search Results";
    $data['navlist'] = $this->MCats->getCategoriesNav();
    $this->load->vars($data);
    $this->load->view('template');
}

  public function about_us()
{
  $this->load->vars($data);
    $this->load->view('template');
}

  public function privacy()
  {
    $this->load->vars($data);
    $this->load->view('template');
}

}

At the moment I can not get to the bottom of the issue.
Thank you for help to all.
#2

[eluser]CroNiX[/eluser]
Are you loading MOrders, whatever that is? Model I assume? Actually, I only see you load the session and cart libraries, so I'm not sure how any of this is working. MCats, MOrders and MProducts don't seem to be loaded here unless they are loaded somewhere else.
#3

[eluser]Ayeyermaw[/eluser]
I don't have the book so I can't give you a specific answer but what I can tell you is that MOrders has not been loaded.
I'm assuming with the name of MOrders, MCats and MProducts that they are models. I'm also assuming that the other two models aren't throwing errors therefore are loaded.

Check application/config/autoload.php (I assume that's where you're loading them from as you haven't done so in the copntroller).



EDIT: Cronix beat me to it :p
#4

[eluser]InsiteFX[/eluser]
@CroNiX, The tutorial has them autoloaded.

There is alot more then that wrong with that tutorial!

I have already converted it to CI 2.1.0 and it was no fun, there are errors even in the view files!

The only thing that I did not convert was the shopping cart because I feel it should be converted over to CI's Shopping Cart Class, someday I'll get around to it.

#5

[eluser]CroNiX[/eluser]
Maybe he forgot MOrders then, because those error messages indicates it doesn't exist. I know this isn't the first time someone has posted problems about that particular tutorial..
#6

[eluser]antoniog[/eluser]
[quote author="CroNiX" date="1337270803"]Are you loading MOrders, whatever that is? Model I assume? Actually, I only see you load the session and cart libraries, so I'm not sure how any of this is working. MCats, MOrders and MProducts don't seem to be loaded here unless they are loaded somewhere else.[/quote]

Yes MOrders is a model and it is loaded by autoload.php like the other models.
#7

[eluser]CroNiX[/eluser]
The problem could be in the model code then, which you should also post.
#8

[eluser]antoniog[/eluser]
[quote author="Ayeyermaw" date="1337271204"]I don't have the book so I can't give you a specific answer but what I can tell you is that MOrders has not been loaded.
I'm assuming with the name of MOrders, MCats and MProducts that they are models. I'm also assuming that the other two models aren't throwing errors therefore are loaded.

Check application/config/autoload.php (I assume that's where you're loading them from as you haven't done so in the copntroller).



EDIT: Cronix beat me to it :p[/quote]

In real MOrders had not been added to autoload.php. Sorry my mistake they are all a little apprehensive as I already work on my project.
#9

[eluser]antoniog[/eluser]
[quote author="InsiteFX" date="1337271446"]@CroNiX, The tutorial has them autoloaded.

There is alot more then that wrong with that tutorial!

I have already converted it to CI 2.1.0 and it was no fun, there are errors even in the view files!

The only thing that I did not convert was the shopping cart because I feel it should be converted over to CI's Shopping Cart Class, someday I'll get around to it.

[/quote]

Thank you.
#10

[eluser]antoniog[/eluser]
[quote author="CroNiX" date="1337271669"]Maybe he forgot MOrders then, because those error messages indicates it doesn't exist. I know this isn't the first time someone has posted problems about that particular tutorial..[/quote]

Yes I have forgot insert MOrders in autoload.




Theme © iAndrew 2016 - Forum software by © MyBB