session or array? session with array?

how to use session with array?




<?php

$var = array(

'1' => array('firstname' => 'something', 'lastName' => 'something more'),

'2' => array('firstname' => 'something2', 'lastName' => 'something more3'),

);

Yii::app()->session['myArray'] = $var;

$gridDataProvider = new CArrayDataProvider(yii::app()->session["myArray"]);?>

?>



how i can (add, edit, delete) more item this session[myArray] ?

or may be i use array not session? may be use model?

sorry i am so newbie, thanks


<?php

$var = array(

array('firstname' => 'something', 'lastName' => 'something more'),

array('firstname' => 'something2', 'lastName' => 'something more3'),

);


$gridDataProvider = new CArrayDataProvider($var);


?>

It can be done without a session and I would suggest not to use a session here.

If you have to add more data you could do it like this:


$moreInfo = array('firstname' => 'Jack', 'lastName' => 'Dull');




array_push($var, $moreInfo);

Hey Dear,

session is array , if you are making custom session array than it’s create array of array. so you have to think on this way.

Thanks

why not just




$_SESSION['1_param']=array('firstname' => 'something', 'lastName' => 'something more');

$_SESSION['2_param']=array('firstname2' => 'something2', 'lastName2' => 'something more2');



rookie84,Pravin Gajera and StasuSS. thanks for reply.

I made like a shopping cart.

Yii::app()->session[‘myArray’] <<< how to set this, like shopping cart.

i am just like temporary array. i wanna set peritem add, edit, and

delete this session.




<?php

  

  $var = array(

'1' => array('firstname' => 'something', 'lastName' => 'something more'),

'2' => array('firstname' => 'something2', 'lastName' => 'something more3'),

);


Yii::app()->session['myArray'] = $var;

$gridDataProvider = new CArrayDataProvider(yii::app()->session["myArray"]);

// yii::app()->session["myArray"].get('1');

?>


<?php $this->pageTitle=Yii::app()->name; ?>


<?php $this->widget('bootstrap.widgets.BootGridView', array(

    'dataProvider'=>$gridDataProvider,

    'template'=>"{items}",

    'itemsCssClass'=>'table table-striped table-bordered table-condensed',

    'columns'=>array(

        array('name'=>'var', 'header'=>'#'),

        array('name'=>'firstname', 'header'=>'First name'),

        array('name'=>'lastName', 'header'=>'Last name'),

        array('name'=>'language', 'header'=>'Language'),

        array(

            'class'=>'bootstrap.widgets.BootButtonColumn',

            'htmlOptions'=>array('style'=>'width: 50px'),

        ),

    ),

)); ?>