Note that there are some explanatory texts on larger screens.

plurals
  1. POCode igniter Cart Class, won't hold cart items in the session
    primarykey
    data
    text
    <p>I am following the ‘build a shopping cart’ tutorial with CI by nettuts. I haven’t even gotten into the first 5 minutes and I’ve got a problem.</p> <p>It appears my sessions system isn’t working and passing the data across. I did some reading and I see CI does not use normal php sessions but stores them in the database using the session ID as the identifier.</p> <p>So I checked, all my database settings are right, and I set up the sessions table and fields as per some stack answers I found. I can see CI writing and storing data into the session table, but the cart doesn't hold items across the pages.</p> <p>I am auto loading</p> <pre><code> $autoload['libraries'] = array('database', 'cart'); $autoload['helper'] = array('form', 'html', 'url'); </code></pre> <p>I set this</p> <pre><code> $config['encryption_key'] = ''; </code></pre> <p>^ my encryption key is made out of letters and a number, if that’s alright to use.</p> <p>I seen this was set to false so I set it to true</p> <pre><code> $config['sess_use_database'] = TRUE; </code></pre> <p>Here is the start of the cart controller…</p> <pre><code> class Dazcart extends CI_Controller { //adds item to shopping cart function Addtocart() { $item = array( 'id' =&gt; '42', 'name' =&gt; 'Octane Lean Build Fast', 'qty' =&gt; 1, 'price' =&gt; 347, 'options' =&gt; array ('flavor' =&gt; 'chocolate') ); $return = $this-&gt;cart-&gt;insert($item); echo "&lt;pre&gt;"; print_r($this-&gt;cart-&gt;contents()); echo "&lt;/pre&gt;"; } function Showcart() { $cartcontents = $this-&gt;cart-&gt;contents(); echo "&lt;pre&gt;"; print_r($cartcontents); echo "&lt;/pre&gt;"; } } </code></pre> <p>Now every time I load /Dazcart/Addtocart it confirms that the item was successfully stored into the cart via the print_r statement.</p> <p>But if I load /dazcart/Showcart the print_r statement just shows an empty array, telling me that he data isn’t being passed across the session. >: (</p> <p>I know this is newbie stuff but I’ve spent hours on it now and I am new to Code Igniter. I just want to figure this out move on so I can learn more and get my site up and running. #frustrated</p> <p>Appreciate your help.</p> <p>Update:</p> <p>Sure here are my session settings in the config file</p> <pre><code> $config['sess_cookie_name'] = 'cisession'; $config['sess_expiration'] = 7200; $config['sess_expire_on_close'] = FALSE; $config['sess_encrypt_cookie'] = FALSE; $config['sess_use_database'] = TRUE; $config['sess_table_name'] = 'ci_sessions'; $config['sess_match_ip'] = FALSE; $config['sess_match_useragent'] = TRUE; $config['sess_time_to_update'] = 300; </code></pre> <p>I noticed $config['sess_use_database'] was false originally I set that to true.</p> <p>If CI doesn't use normal php sessions, how do I do a session dump?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload