I've got a Drupal site which uses a custom field for a certain type of node (person_id
) which corresponds to a particular user. I want to create a view so that when logged in, a user can see a list of nodes 'tagged' with their person_id
. I've got the view working fine, with a url of my-library/username
but replacing username
with a different username shows a list of all nodes tagged with that user. What I want to do is stop users changing the URL and seeing other开发者_如何学C users' tagged nodes. How can I do this? Is there somewhere where I can dictate that the only valid argument for this page is the one that corresponds with the current logged in user's username?
person_id = uid?
In this case, add argument with user:uid, then in Validation options select PHP Code, read comment of this field carefully:
Enter PHP code that returns TRUE or FALSE. No return is the same as FALSE, so be SURE to return something if you do not want to declare the argument invalid. Do not use . The argument to validate will be "$argument" and the view will be "$view". You may change the argument by setting "$handler->argument".
Add this code:
global $user;
$account = user_load('name'=>arg(1));
$handler->argument = $user->uid;
return $account->uid == $user->uid;
I'm not sure how you have setup your view, which gives some different options to solve this. A way that should work would be to set the default argument be the logged users id/username and remove the argument from the url.
Alternatively you could create your own filter which requires some work with the views API, but gives more control.
精彩评论