[SOLVED] RBAC Using "expression"

Hello

i have in the controler the next code




<?php

class UsuariosController extends CController

....

	public function accessRules()

	{

		return array(


                        array('allow',  

				'actions'=>array('list','show'),

				'expression'=>'Seguridad::tiene_rol(''SEG_CONSULTA'')',

			),

....

...




and the class Seguridad in folder components




<?php

/* 

 * Retorna true si el usuario tiene el rol

 * 

 */

class Seguridad {


    public function tieneRol($rol){


       $id_rol=Roles::model()->find('nombre=:nombre', array(':nombre'=>$rol));


       $usuRol=UsuarioRoles::model()->find('usu_id_usuario=:id_usuario and rol_id_rol=:id_rol' , array(':id_usuario'=>Yii::user->getState('id_usuario'),':id_rol'=>$id_rol));


       return !($usuRol === null);

       


    }

}


?>



when show list view, the page is blank, no show anything

what is bad? ???

sorry for mi spaninglish

I think you should declare your class method as static to properly use it in your code:


public static function tieneRol($rol){

UPD: typo?

put




'expression'=>Seguridad::tieneRol('SEG_CONSULTA'),



and works

thanks DARK

Horacio,

Check the declared function name and the name you call in ‘expression’ key:


class Seguridad {


    public function tieneRol($rol){


'exp​ression'=>Seguridad::tiene_rol('SEG_CONSULTA'),

Just a little typo :)

yes yes Newbie Newbie

thanks!!!!