By airor on
I've tried searching first, and the only responses seem to be a year old.
Is there a way to control access to pages? I have a little php script that I want to use to do things like display payroll information.
I can't let everyone see the payroll obviously, and in addition, I definitely can't let everyone input the payroll information...
The handbook doesn't talk about access control as far as I know, and I understand that I can restrict access to modules, but not content pages.
Does access control in drupal exist yet? Or is this the heel of the mighty Achilles.
Thanks.
Comments
What you need is a little nodeperm_role
What you want to do is go get the most recent cvs for Drupal and nodeperm_role.module (anything older won't work).
This will allow you to use those nifty permissions roles that you created (or will create) to limit who can and cannot see certain pages.
Another great thing you can do is even limit which users have access to the link to see those pages by using user created blocks.
Create a seperate block for each group who has access to your site.
For instance I have a site where people can create an account but still be limited to certain information until they subscribe to it. So I have 3 seperate blocks: Logged Out, Logged In, and Subscriber.
As you create each block set the 'input format' to php and insert the following code (of course you'll have to modify it to fit your own role names and page names).
This is for the group you want to allow access
The following code is for everyone that's logged out.
Hope this helps.
And viola!
-Varr
I need to get out more..
I need to get out more.. that was downright sexy.
Although this is probably a php issue rather than a drupal issue, I am a little confused as to the purpose of the :
else {
$roles = $user->roles;
}
If the if is_array($user->roles) wasn't there, wouldn't the foreach statement cover the situation?
I'll try out the newest version of 4.6 tonight. I haven't yet, as I'm new to drupal and there seem to be a lot of issues with the new version, hehe :).
Thanks.
foreach array issue
I know that without that is_array check I have had problems where it pops an error saying something like "expected an array at blah blah blah", so I threw that in there and viola. PFM (pure f'ing magic).
Yeah, I'm kinda new to Drupal myself (about 2 weeks now), but I really like it, especially now that they've introduced the new e-commerce module, WITH subscriptions!
Don't get me started.
Anyway, good luck and let me know how that works out for ya.
-Varr
"Another great thing you can
"Another great thing you can do is even limit which users have access to the link to see those pages by using user created blocks."
I am assuming that you are talking about menu links to the protected pages.
When you create these custom access blocks (with your PHP code), how do you create/display the menu links (in your created blocks) to these protected pages? I don't think there is a way to use the drupal menu module to create and maintain menu links in custom blocks. Do you manually put the html code for these links in the created blocks?
If so it would be nice if there was a mod that allowed similar functionality in drupal menu blocks. In other words you could then choose which roles are allowed to view a drupal menu block.
Protected links
Yes,
I am referring to menu links to protected pages.
Now don't take anything I say here as gospel, I'm still fairly new at this, but...
Whenever you create a new menu or block, you aren't intrinsically given the ability to select who can see that menu or block.
And yes, until someone creates a module with the ability to assign access permissions to blocks, the method I used is a very effective way, although I'm sure someone else a little more familiar with Drupal could give you various other ways of doing it.
To clarify (REFER TO CODE ABOVE ↑):
I probably should have been a little more specific about this, but for the blocks that contained unprotected menu links you would use (and I believe that this is the manually created html you were referring to):
...and for blocks that had protected links you could use:
If that doesn't clear things up let me know.
-Varr