CodeIgniter Forums

Full Version: my session did not show
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]yudahebat[/eluser]
I have a controller
Code:
function v_cart()
    {
        $data['css']         = $this->css;
        $data['base']         = $this->base;
        $data['menu_web']     = $this->menu;
        $data['myrobots']     = '<meta name="robots" content="noindex,nofollow">';
        $data['mywebtitle'] = 'mrputucar | Your cart';
        
        $this->output->enable_profiler(TRUE);
        $this->session->set_userdata(array('nama' => $this->input->post('nama'),'photo' => $this->input->post('photo'),'harga' => $this->input->post('harga')));
    
        $this->load->view('v_cart',$data);
    }

and views

Code:
<table width="645" border="0" cellpadding="0" cellspacing="0" class="tabel" >
                <tr>
                    <td width="130" class="tabel" align="center"><p>Car Type</p></td>
                    <td width="110" class="tabel" align="center"><p>Rent date</p></td>
                    <td width="110" class="tabel" align="center"><p>Return date</p></td>
                    <td width="80" class="tabel" align="center"><p>Duration</p></td>
                    <td width="100" class="tabel" align="center"><p>Price/day</p></td>
                    <td width="110" class="tabel" align="center"><p>Suhtotal</p></td>
                </tr>
                &lt;?php foreach ($this->session as $row)
                      {?&gt;
                <tr>
                    <td width="130" class="tabel"><p>&lt;?= row->$this->session->userdata('nama');?&gt;</p></td>
                    <td width="110" class="tabel"><p>..</p></td>
                    <td width="110" class="tabel"><p>..</p></td>
                    <td width="80" class="tabel"><p>..day</p></td>
                    <td width="100" class="tabel"><p>$ &lt;?= row->$this->session->userdata('harga');?&gt;</p></td>
                    <td width="110" class="tabel"><p>$..</p></td>
                </tr>
                &lt;? } ?&gt;
                <tr>
                    <td colspan="4" class="tabel2"><p>&lt;?php echo form_submit('', 'Update your Cart'); ?&gt;</p></td>
                    <td  class="tabel2"><p>Total</p></td>
                    <td  class="tabel2"><p>$...</p></td>
                </tr>
                    
                </table>
but when I run it, its not show anything..
help me please

El Forum

[eluser]Dam1an[/eluser]
I think you want to pass it through in the data array
Sessions are meant for maintaining state between requests, but you're still in the same request when you load the view

Does this not give you any errors, assuming you have reporting enabled

El Forum

[eluser]yudahebat[/eluser]
yep its error
it shown like this
Code:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in C:\xampp\htdocs\CI2\system\application\views\v_cart.php on line 25

El Forum

[eluser]pistolPete[/eluser]
Did you enable error_reporting?
Are short open tags (&lt;?) enabled on your server?

El Forum

[eluser]sl3dg3hamm3r[/eluser]
Why not copying out this line 25 for the community? Actually, everything is said in the error-report.
Guess there is also soon a sticked post "how to debug correctly in php" necessary, as you would find it in every other php-forum...

El Forum

[eluser]yudahebat[/eluser]
line 25 :
Code:
<td width="130" class="tabel"><p>&lt;?= row->$this->session->userdata('nama');?&gt;</p></td>

El Forum

[eluser]Thorpe Obazee[/eluser]
[quote author="sl3dg3hamm3r" date="1245175860"]Why not copying out this line 25 for the community? Actually, everything is said in the error-report.
Guess there is also soon a sticked post "how to debug correctly in php" necessary, as you would find it in every other php-forum...[/quote]

They want you to guess.

El Forum

[eluser]Thorpe Obazee[/eluser]
[quote author="yudahebat" date="1245172126"]

Code:
<table width="645" border="0" cellpadding="0" cellspacing="0" class="tabel" >
                <tr>
                    <td width="130" class="tabel" align="center"><p>Car Type</p></td>
                    <td width="110" class="tabel" align="center"><p>Rent date</p></td>
                    <td width="110" class="tabel" align="center"><p>Return date</p></td>
                    <td width="80" class="tabel" align="center"><p>Duration</p></td>
                    <td width="100" class="tabel" align="center"><p>Price/day</p></td>
                    <td width="110" class="tabel" align="center"><p>Suhtotal</p></td>
                </tr>
               [b] &lt;?php foreach ($this->session as $row)
                      {?&gt;[/b]
                <tr>
                    <td width="130" class="tabel"><p>&lt;?= row->$this->session->userdata('nama');?&gt;</p></td>
                    <td width="110" class="tabel"><p>..</p></td>
                    <td width="110" class="tabel"><p>..</p></td>
                    <td width="80" class="tabel"><p>..day</p></td>
                    <td width="100" class="tabel"><p>$ &lt;?= row->$this->session->userdata('harga');?&gt;</p></td>
                    <td width="110" class="tabel"><p>$..</p></td>
                </tr>
                &lt;? } ?&gt;
                <tr>
                    <td colspan="4" class="tabel2"><p>&lt;?php echo form_submit('', 'Update your Cart'); ?&gt;</p></td>
                    <td  class="tabel2"><p>Total</p></td>
                    <td  class="tabel2"><p>$...</p></td>
                </tr>
                    
                </table>
but when I run it, its not show anything..
help me please[/quote]

yudahebat, did you really want to iterate through the CI Session object?

El Forum

[eluser]yudahebat[/eluser]
actually I want to looping my session
so every I input data from another views, the table add 1 data without replace last entry data

El Forum

[eluser]Thorpe Obazee[/eluser]
[quote author="yudahebat" date="1245235773"]actually I want to looping my session
so every I input data from another views, the table add 1 data without replace last entry data[/quote]

did you ever try looking into $this->session? If you didn't use print_r($this->session). It has a lot lot more than what you need.

What you'd want is $this->session->userdata.
Pages: 1 2