在 drupal 视图中将 cck 字段作为参数传递的问题
我不太确定我做错了什么,基本上在我的 UI 视图中,我传递了一个名为 day 的 cck 字段作为参数,我选择了“提供默认参数”并在选择 php 代码选项后输入了下面的 phpcode。我想要实现的是,如果用户在实时预览中输入 day1,则只应显示与该天相关的信息,但是,我不确定我做错了什么?
$numDays=7;
for($i=0; $i<$numDays; $i++) {
$futuredate = date('d-m-Y', strtotime('+' . strval($i) . ' days'));
return "day"$i;
}
I am not quite sure of what i am doing wrong, basically in my view ui, i passed a cck field called day as argument, i selected "Provide default argument" and entered the phpcode below after selecting the php code option. What i am trying to achieve is that if the user enters day1 for example in the live preview, only information relating to that day should be displayed however, i am not sure what i am doing wrong?
$numDays=7;
for($i=0; $i<$numDays; $i++) {
$futuredate = date('d-m-Y', strtotime('+' . strval($i) . ' days'));
return "day"$i;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您能解释一下您的逻辑试图做什么吗?正如它的编码所示,它只会返回“day0” - 循环中没有条件语句,因此每次都会在第一次迭代时遇到返回行。我假设您想根据当前日期提供默认参数?如果是这样,您可以使用日期函数获取一周中的当前日期作为数字。我猜您正在寻找类似的东西(这就是您在代码中所需的全部内容):
如果未提供参数,它将返回“dayX”,其中 X 是一周中的当前日期。
Can you please explain what your logic is attempting to do? As it's coded it will only return "day0" - there is no conditional statement in your loop, so it's going to hit the line that says return on the first iteration every time. I assume you want to provide a default argument based on whatever the current date is? If so you can get the current day of a week as a number with the date function. I'm guessing you're looking for something like this (this is all you need in your code):
That'll return "dayX" where X is the current day of the week if an argument isn't provided.