Welcome Guest, Not a member yet? Register   Sign In
$_SESSION blank in included controller
#1

[eluser]dcallan[/eluser]
Hi all, strange problem, I have a page called myfavourites, and when I load the regular page, the PHP session var comes out fine, but when I included an myfavourites/ajaxview controller, the session array is empty within that controller, when I view the master myfavourites page. What's strange too is that when I load the ajax controller directly the session variable is available and populated. How come the included file/controller is not getting the session vars. They are set in My_Controller, which both myfavourites/index and myfavourites/ajaxview subclass from

Code:
<table border="1">
    <tr>
        <td>
            Add a product to your favourites
            &lt;input type="text" id="productIDtoaddtofavourites"&gt;
            &lt;input type="submit" value="Add to favourites" id="addtofavourites"&gt;
        </td>
        <td>
            &nbsp;
        </td>
    </tr>
    <tr>
        <td id="ajaxfavourites" valign="top">
            &lt;? include site_url('myfavourites/ajaxview'); ?&gt;
        </td>
        <td id="ajaxquickbasket" valign="top">
            &lt;? include site_url('mybasket/ajaxquickview'); ?&gt;
        </td>
    </tr>
</table>

Any ideas? thanks in advance.
#2

[eluser]bubbafoley[/eluser]
you can't include a controller like that. you need to use javascript.

example w/ jQuery
Code:
<table border="1">
    <tr>
        <td>
            Add a product to your favourites
            &lt;input type="text" id="productIDtoaddtofavourites"&gt;
            &lt;input type="submit" value="Add to favourites" id="addtofavourites"&gt;
        </td>
        <td>
            &nbsp;
        </td>
    </tr>
    <tr>
        <td id="ajaxfavourites" valign="top"></td>
        <td id="ajaxquickbasket" valign="top"></td>
    </tr>
</table>

&lt;script type="text/javascript"&gt;
$(function() {
    $.get('&lt;?php echo site_url('myfavourites/ajaxview') ?&gt;', function(data) {
        $('#ajaxfavourites').html(data);
    });
    $.get('&lt;?php echo site_url('mybasket/ajaxquickview') ?&gt;', function(data) {
        $('#ajaxquickbasket').html(data);
    });
});
&lt;/script&gt;

You can also use curl, file_get_contents() or fopen() but it's harder to maintain the session that way.




Theme © iAndrew 2016 - Forum software by © MyBB