‌‌R‌‌‌.
‌‌R‌‌‌.

Reputation: 2954

How to check drupal user role in module written by Zend Framework

I have written a web application using Zend framework, and I convertered it to the drupal module using ".module" file.

But I need to authorize current drupal user in that module.

How could I check the drupal user role in Zend?

By the way I find out Drupal has its own session handler to store data in database and zend use default handler which store sessions data into file system. So it make them separate.

Any solution?

Upvotes: 0

Views: 100

Answers (2)

Clive
Clive

Reputation: 36956

It's considered bad practice to check the roles array itself in Drupal, the correct method is to assign an appropriate permission to that role, and check for that permission with user_access(), e.g.

if (user_access('an appropriate permission')) {
  // User is authorised.
}

Upvotes: 2

Ben
Ben

Reputation: 1535

So you actually have a Drupal module.

Try

<?php
global $user;
if (in_array('administrator', array_values($user->roles))) {

}

Upvotes: 0

Related Questions