PHP, Yii framework RBAC: write rule to create posts

I have tried to implement RBAC in my yii2 application, and I’ve followed this tutorial:

I have created an “admin” role, and assigned it the “createPost” permission, but my “admin” user can still not create posts. If I understood this correctly, now I have to implement a rule for creating posts and assign it to this permission. I can see that there is already an “AuthorRule”:

public function execute($user, $item, $params)
   return isset($params['post']) ? $params['post']->createdBy == $user : false;

but I’m completely new to PHP and Yii and don’t know how to make another rule for creating posts.

Source: stackoverflow-php

Yii2 creates new session instead of opening existing

I am working on a simple logic of storing my shopping cart in session using Yii2 native yiiwebSession.
Every time I add an item to a cart I call a method:

public function actionAdd( ) {

    $id = Yii::$app->request->get('id');
    $product = Product::findOne($id);

    $session = Yii::$app->session;

    $cart = new Cart();

    $this->layout = false;
    return $this->render('cart-modal', compact('session'));

this method works with a Cart model and adds my item to the session:

public function addToCart($product, $qty = 1) {

    if(isset($_SESSION['cart'][$product->id])) {
        $_SESSION['cart'][$product->id]['qty'] += $qty;
    } else {
        $_SESSION['cart'][$product->id] = [
            'qty' => $qty,
            'title' => $product->title,
            'price' => $product->price,
            'image' => $product->image,

and all goes well until I try add another item.
Then Yii instead of opening existing session creates a new one with this last item I’ve add. What can be the reason of this kind of behavior?

I’m working on a local web server OpenServer and haven’t changed any setting that might be related to sessions.

Source: stackoverflow-php