[eluser]alectrash[/eluser]
Hi There
I have been going round in circles with this for a good while and since its Friday though I would put on here for help. I HAVE ALREADY FOUND A SOLUTION TOO but not sure if its the right thing to do.
I have extended the Codeigniter cart class to have an extra function to retrieve the weight of items in the basket. I store the weight in an extra index in the cart array. Its all working on localhost but not on my production server.
I have a basket.php controller which calls a function in the My_Cart class to get the weight.
Code:
<?php
class Basket extends Controller {
function __construct()
{
parent::Controller();
$this->load->model('basket_model');
$this->load->helper('url');
$this->load->library('form_validation');
}
function index()
{
echo $this->cart->weight();
}
}
and then this is my MY_Cart.php file
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* Extenstion of cart class
*/
class MY_Cart extends CI_Cart
{
function MY_Cart()
{
parent::CI_Cart();
}
function _update($items = array())
{
//existing cart _update code goes here with a few changes to update weight, tax, vouchers on basket etc
}
function _save_cart()
{
//existing _save_cart code goes here with a few changes to save weight, tax and other stuff
}
function weight()
{
return 10;
}
}
?>
On localhost (WAMP) (PHP5.3) this works but on production server (linux) (php5.2.7) I get the following error:
Code:
Fatal error: Call to undefined method CI_Cart::weight() in /var/www/vhosts/somedomain.co.uk/subdomains/thewebapp/httpdocs/system/application/controllers/basket.php on line 14
I have simplified the code above by taking lots of other non related stuff out but this is essentially the code which is not working. The _save_cart() and _update() method are adaptations of functions already in the native CI cart class and I have changed these to extend the functionality of the basket. These work fine.
I have already found a solution which is to add an empty function for weight() in the actualy codeigniter cart.php class.
in system/libraries/Cart.php i have added in
Code:
function weight()
{
///empty function to get the associated function in MY_Cart.php to work.
}
In finding this solution does this mean that you can only extend functions that are already in the native CI class? or is it possible to extend a class and add new functions without declaring them in the class your extending also?
Any help/advice much appreciated.
Thanks
Matthew Fedak