Drupal 使用具有 CCK 自定义字段的视图
我有一个 Drupal 站点,它使用与特定用户相对应的某种类型的节点 (person_id
) 的自定义字段。我想创建一个视图,以便用户在登录时可以看到用其 person_id
“标记”的节点列表。我的视图工作正常,网址为 my-library/username
但用不同的用户名替换 username
会显示标记有该用户的所有节点的列表。我想要做的是阻止用户更改 URL 并查看其他用户的标记节点。我该怎么做?是否有地方我可以指定该页面的唯一有效参数是与当前登录用户的用户名对应的参数?
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
person_id = uid?
在这种情况下,添加带有 user:uid 的参数,然后在验证选项中选择 PHP 代码,仔细阅读该字段的注释:
添加此代码:
person_id = uid?
In this case, add argument with user:uid, then in Validation options select PHP Code, read comment of this field carefully:
Add this code:
我不确定您如何设置视图,这提供了一些不同的选项来解决此问题。一种可行的方法是将默认参数设置为登录的用户 ID/用户名,并从 url 中删除该参数。
或者,您可以创建自己的过滤器,这需要使用视图 API 进行一些工作,但可以提供更多控制。
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.