Yii Framework Forum: Access Rules On Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Access Rules On Yii Rate Topic: -----

#1 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 25 January 2013 - 05:48 AM

Im having trouble with my access rules in my controller. Im retrieving list of pages from my database in an array form.

Im using this PDO stement to get the list of pages that can be accessed by my user.

public function getPage() {
$user = CHtml::encode(Yii::app()->user->name);

include 'DbHandler.class.php';

$connectionString[0] = Yii::app()->params['dbhandler'];
$dbhandler3 = new DBHandler($connectionString[0]);
$dbhandler3->open();

$dbhandler3->prepare("SELECT AccessPage FROM accessrights where UserName = '$user'");
$dbhandler3->execute();
$this->result2 = $dbhandler3->fetchAllData();
$dbhandler3->close();

$yourarrayname = array();
while ($row = $dbhandler3->fetchAllData()) {
$yourarrayname[] = $row['AccessPage'];
}

$this->access = $yourarrayname;
}

$this->access = $yourarrayname;

so I store my array list of pages in a variable called $this->access but when I use the $this->access, I can still access other pages which is not even listed in my database.


here is my usage of $this->access in accessRules():



public function accessRules() {
if ($this->user == 'Guest') {
$this->user = 'admin';
}
$this->getPage();

return array(
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions' => array('show', 'show'),
'users' => array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions' => array('admin', 'delete', "register"),
'users' => array('gago'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions' => $this->access,
'users' => array("admin"),
),
array('deny', // deny all users
'users' => array('*'),
),
);
}

Any solution for this, or do you encounter the same situations like this?
0

#2 User is offline   jr_jags 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 38
  • Joined: 05-November 12
  • Location:Philippines

Posted 25 January 2013 - 11:22 PM

I just solved this problem,

I changed my PDO statement to:
public function fetchArrayData()
{
return $this->_stmt->fetchAll(PDO::FETCH_COLUMN, 0);
}

And this is my getPage function:

public function getPage() {
$user = CHtml::encode(Yii::app()->user->name);

include 'DbHandler.class.php';

$connectionString[0] = Yii::app()->params['dbhandler2'];
$dbhandler3 = new DBHandler($connectionString[0]);
$dbhandler3->open();

$dbhandler3->prepare("SELECT AccessPage FROM accessrights where UserName = '$user'");
$dbhandler3->execute();
$this->access = $dbhandler3->fetchArrayData();

}
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users