0

I am making custom shop module for my website and my script breakes all pages where it is. The command what breaks it is: $session =& JFactory::getSession(); (Code putted in default.php). I cant put this in helper as i update the value and i need the updated one. So what i mean with breaks, the template gets broken and leaves the module only. Thank you.

EDIT: The code

$session =& JFactory::getSession();

if($_GET['additem'] != ""){
    for($i = 0; $i < count($items); $i++){
        if($items[$i][0] == $_GET['additem']){
            $id = $i;
        }
    }

    $cart = $session->get('cart', array());
    $cart[count($cart)] = $id;

    $session->set('cart', $cart);
}else{

    $cart = $session->get('cart', array());

}

echo "<table class='table table-hover'>";
    echo '<tr>';
        echo '<th>Id</th>';
        echo '<th>Name</th>';
        echo '<th>Price</th>';
    echo '</tr>';

    for($i = 0; count($cart); $i++){
        echo '<tr>';
            echo '<td>' . $items[$cart[$i]][0] . '</td>';
            echo '<td>' . $items[$cart[$i]][1] . '</td>';
            echo '<td>' . $items[$cart[$i]][2] . '</td>';
        echo '</tr>';
    }

echo '</table>';
4
  • JFactory::getSession() only gets the session object so I doubt this is breaking your site unless you've edited Joomla's core session API file. Could you possibly add a little more code to your question as it will most likely be something else causing your page break
    – Lodder
    Mar 2 '15 at 16:51
  • Didnt edit joomla stuff. Only my module. I commented the session part and everything went perfectly. Check edit. Mar 2 '15 at 16:52
  • If you use $session = JFactory::getSession(); var_dump($session); exit; .... do you get any data returned?
    – Lodder
    Mar 2 '15 at 17:04
  • Yes i do. $session works. but $session/$session->get/$session->set takes too much resources or something that loads the page long and breaks it. Mar 2 '15 at 17:11
-1

Infinite for loop...

for($i = 0; count($cart); $i++){

should be

for($i = 0; $i < count($cart); $i++){

Forgot the $i < count.

2
  • Can you show what actually fixed it? Mar 3 '15 at 15:18
  • Second for loop. for($i = 0; count($cart); $i++){ to for($i = 0; $i < count($cart); $i++){. Forgot the $i < count. Mar 3 '15 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.