yii2: Using Rules with RBAC

Hi,

i want to use RBAC

i am following the documentation on yii2

http://www.yiiframework.com/doc-2.0/guide-security-authorization.html

but the part that concern Using rule, i want to know how name the files (with specific code) and where put those files in order to implement the updateownpost.

Thank

Link 1 and Link 2 will helps you for understanding RBAC.

PHP Notice – yii\base\ErrorException

Undefined variable: post

1. in C:\wamp\www\Projet_pred\controllers\FiliereEtabController.php at line 95


8687888990919293949596979899100101102103104





 


    /**


     * Updates an existing FiliereEtab model.


     * If update is successful, the browser will be redirected to the 'view' page.


     * @param integer $id


     * @return mixed


     */


    public function actionUpdate($id)


    {


      if (\Yii::$app->user->can('updatePost', ['post' => $post])) {


       $isStudent = Yii::$app->session->get('user_id'); //echo $isStudent;


        $mode= FiliereEtab::find()->andWhere(['id_etab'=>$isStudent])->one();


    $id = $mode->id_fil;


    $model = $this->findModel($id);


 


        if ($model->load(Yii::$app->request->post()) && $model->save()) {


            return $this->redirect(['view', 'id' => $model->id_fil]);


        } else {


            return $this->render('update', 

$post is undefined.

i specifie $post but condition return false

public function actionUpdate($id)

{


  $isStudent = Yii::$app->session->get('user_id'); //echo $isStudent;


  $post = FiliereEtab::find()->andWhere(['id_etab'=>$isStudent])->all();


  if (\Yii::$app->user->can('updatePost', ['post' => $post])) {


  // $isStudent = Yii::$app->session->get('user_id'); //echo $isStudent;


   // $mode= FiliereEtab::find()->andWhere(['id_etab'=>$isStudent])->one();


//$id = $mode->id_fil;


$model = $this->findModel($id);





    if ($model->load(Yii::$app->request->post()) && $model->save()) {


        return $this->redirect(['view', 'id' => $model->id_fil]);


    } else {


        return $this->render('update', [


            'model' => $model,


        ]);


    }


}


}

[color="#FF0000"]/*

Please use the CODE tag.

You see "<>" button on the toolbar of the editor which has "Insert code snippet" hint?

Click on it, then it will put a pair of code tags in the text area. Put your code between them.

*/[/color]

So, what do you have for the rule? Does it handle $post appropriately? Or, are you passing an appropriate $post to the rule?




i implement the rule by following this link instructions http://www.yiiframework.com/doc-2.0/guide-security-authorization.html

and i have to my databse, in table auth_rule this line 

name : isAuthor

data: O:19:"app\rbac\AuthorRule":3:{s:4:"name";s:8:"isAuthor";s:9:"createdAt";i:1456917036;s:9:"updatedAt";i:1456917036;}


after, for my example,  i take all line of a table (my ex: filieretab) in  database, that put by an user to variable $post 




The following code is from the guide:

Note that “$params[‘post’]” must be an ActiveRecord object that represents the current blog post in that particular sample scenario.

Are you handing blog posts? No. Your are dealing with “Etab” or something like that. Why don’t you adjust the example to your project? Just copy-and-pasting will never do the job for you. Try harder to understand how things work.

Anyway, you have to pass a single instance of object to the rule. You are trying to pass an array of objects.




it is ok now!

i find the solution

thank