Yii Framework Forum: Need help with converting this - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Need help with converting this Rate Topic: -----

#1 User is offline   frocco 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 232
  • Joined: 17-February 10

Posted 22 October 2010 - 02:59 PM

Hello,

I am having a hard time converting this to yii.
I know how to change the session syntax, but how do I change this class to a singleton?

Where would I install this class once it is converted?

Sorry, but I am a newbie to yii and this is a bottleneck for me.

Thanks in advance.

Attached File(s)

  • Attached File  Cart.php (14.78K)
    Number of downloads: 5

Regards,

Frank
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 23 October 2010 - 05:13 AM

If i where you i'd rewrite the cart. You can maybe borrow the basic concept but i'd refactor the interface.

Basic idea:

class MyCart extends CApplicationComponent
{
    public function init() {  /* initialize the cart, maybe set up session if you don't autostart it */ }

    public function add($article) { /* code to add an article here */ }
    public function total() { /* code to calculate total price of articles here */ }
    // ... 
}


Setup as application component in you configuration:

'components'=>array(
    'cart'=>'array(
        'class'=>'application.components.MyCart',
    ),
    ..



Access from everywhere like:

echo Yii::app()->cart->total();

0

#3 User is offline   frocco 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 232
  • Joined: 17-February 10

Posted 25 October 2010 - 07:23 AM

Thanks Mike, that helped me a lot.
SI am still new to yii.
Regards,

Frank
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users