视图、参数和块
我目前很难理解 Drupal 的视图在将视图显示为块时如何处理参数。我有一些简单的页面(例如 studios/bremen)和一些与这些页面匹配的用户(例如用户名:bremen)。用户可以在 studios/* 页面上发布需要预告的新闻。
我是否必须使用参数处理程序将 arg(1) 中的 node_id 转换为相应的用户名,还是有更简单的方法?
我希望我能解释我的问题,这样你就能理解……这整个观点争论的事情对我来说有点奇怪。
I currently having trouble to get my head around how Drupal's views work with arguments when displaying a view as a block. I have a few simple pages (eg studios/bremen) and a few users that match those pages (eg username: bremen). Users can post news which need to be teasered on the studios/* page.
Do I have to use an Argument Handler that translates the node_id in arg(1)
to the corresponding username, or is there an easier way?
I hope i could explain my problem so you can understand… this whole view argument thing feels kinda weird to me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
arg(1) 不会是用户名或 UID,并且不会按您期望的方式工作。我们可以尝试的是进行查找并返回以迂回方式提供默认参数值。
如果参数不存在则采取的操作:设置为空文本,或 404,无论您的偏好如何。
为验证器提供 PHP 代码:
您需要确保的是,arg(1) 作为某些页面上的用户名不会包含(或允许)字符通过,从而导致 SQL 注入。
用户名模式可以使用 Pathauto 进行控制。但这并不能阻止某人在 URL 中输入垃圾内容,而且 Drupal/Views 应该能够避开 URL 中的字符。您可以通过设置 ACTION TO TAKE IF ARGUMENT DOES NOT VALIDATE 来测试,以显示 404 页面或空文本。
尝试一下并使用视图的预览部分,看看它是否为您返回任何内容。我是凭空做这件事的,但我总是用不同类型的内容或搜索做类似的事情。
您还可以尝试将验证器设置为用户,并允许数字 UID 和字符串用户名。我没有使用过该设置,但它很可能也会起作用。
arg(1) won't be a username or UID and not work the way you expect. What we can try though is to do a lookup and return to provide the default argument value in a roundabout way.
ACTION TO TAKE IF ARGUMENT IS NOT PRESENT: set to Empty text, or, 404, whatever your preference.
Provide PHP code for the Validator:
The part you want to make sure about here is that arg(1) being a username on certain pages will not contain (or allow) characters to pass through causing a SQL injection.
Username patterns can be controlled with Pathauto. This won't stop someone from entering junk into the URL though, and Drupal/Views should be able to sidestep characters in the URL. You can test that by setting ACTION TO TAKE IF ARGUMENT DOES NOT VALIDATE to display a 404 page, or, empty text.
Try this out and use the preview part of Views and see if it returns anything for you. I did this off the top of my head, but I do similar things all the time with different types of content or searches.
You can also try setting the Validator to User, and Allow both numeric UIDs and string usernames. I haven't used that setting, but it most likely will work as well.