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: http://www.yiiframework.com/doc-2.0/guide-security-authorization.html#rbac.

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