[SOLVED] Neos Plugin Session Error 500 (again)

Hey guys,

I have already opened a thread which deals with this topic, but I think I have not formulated it well enough.

I have a controller that stores data into a session. It works.

When reading out the session everything is displayed correctly. However, only the first time :frowning:
The second time I get the Error 500

Form to add:

<f:form action="addItem" objectName="item" controller="Cart" package="NeosCommerce.Cart">
    <f:form.hidden property="text" value="This is the text" />
    <button type="submit">Add to cart</button>
</f:form>

AddTo Action in my controller:

/**
* @Flow\Scope("session")
*/
class CartController extends ActionController
{

/**
 * @var array
 */
protected $items = array();

/**
 * @param array $item
 * @return void
 * @Flow\Session(autoStart = TRUE)
 */
public function addItemAction($item) {
    $this->items[] = $item;
    $this->redirectToUri('/');
}

//The following action are also here!

}

With this function I get the data:

/**
 * @return void
 */
public function miniCartAction() {
    $cart = $this->items;
    $cartcount = count($cart);
    
    if ($cartcount>0) {
        $sum = FALSE;
        $sum = intval($sum);
        foreach ($cart as $dat) {
            $quantity = intval($dat["quantity"]);
            $sum += $quantity;
        }
        $sum = $sum;
    } else {
        $sum = '0';
    }
    $this->view->assign('result', $sum);
}

The miniCart Template:

{namespace fusion=Neos\Fusion\ViewHelpers}
{namespace neos=Neos\Neos\ViewHelpers}
<div class="mini-cart">{result}</div>

If I use

return $sum;

instead of

$this->view->assign('result', $sum);

it works perfectly.

As soon as I implement something in Fluid, it does not work anymore.

I hope someone can help me.

Thx,
Pat

And this is the error.log

2017/08/04 05:33:24 [error] 7#7: *3 FastCGI sent in stderr: “PHP message: PHP Fatal error: TYPO3Fluid\Fluid\View\AbstractTemplateView::getCurrentParsedTemplate(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition “Cart_action_miniCart_f5921b8d0c04142206091fba464e5b9cecd419c3” of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition in /application/Packages/Libraries/typo3fluid/fluid/src/View/AbstractTemplateView.php on line 364” while reading response header from upstream, client: 172.22.0.1, server: , request: “GET /mini-warenkorb.html HTTP/1.1”, upstream: “fastcgi://172.22.0.2:9000”, host: “localhost”, referrer: “http://localhost/mini-warenkorb.html

I think that is the solution: http://php-autoloader.malkusch.de/de/Eigenschaften/Session/
But how can I implement/use this in flow?

First thing to try is not to make the controller session scope. Create a separate Cart object that is scope session. Not sure if that actually fixes it but would be my first try.

I don’t think the linked article will really help.

Thank you Christian! This works fine!

1 Like