Welcome Guest, Not a member yet? Register   Sign In
beginner-question OOP - CI
#1

[eluser]Unknown[/eluser]
Hi /*/g,
I'am new to CI and almost new to OOP. I`ve decided building our new Online-Shop the oop-way using a MVC-Framework. I wonder how I write the following with CI.

I have (for examble) two objects: a shoppingcart and a article.

Code:
<?php

class artikel {

        public $ArticleNumber;
        public $Artikel;

        public function __construct($ArtikelNumber, $Artikel) {

                $this -> ArtikelNumber = $ArtikelNumber;
                $this -> Artikel = $Artikel;
        }

        public function __tostring() {

                return "Artikel {$this -> ArtikelNumber} {$this -> Artikel}";
        }

}

class cart {

        private $inventory;

        public function __construct() {

        }

        public function add($item) {

                $this -> inventory[] = $item;
                print $item . " added\n";
        }

        public function show() {

                foreach ($this -> inventory as $item) {

                        print "Warenkorb: {$item}\n";
                }
        }
}

$cart = new cart();

$cart -> add(new artikel(10, 'Buch'));
$cart -> add(new artikel(110, 'Handtuch'));
$cart -> add(new artikel(210, 'Zahnpasta'));
$cart -> add(new artikel(510, 'iPod'));


$cart -> show();

?>

How do I write this with CI? I understand I have to make a shoppingcart-model (extends Model) and a article-model and load it with

Code:
$this->load->model(cart);

but how can I work with these loaded objects? how do I add article-objects to my cart?

greetings from germany to the CI-Community!
Bad Pussycat ;-)


Messages In This Thread
beginner-question OOP - CI - by El Forum - 03-29-2008, 01:08 PM
beginner-question OOP - CI - by El Forum - 03-29-2008, 02:24 PM



Theme © iAndrew 2016 - Forum software by © MyBB