日历 - 下一个链接
所以我目前使用这个 http://davidwalsh.name/php-calendar 作为我的日历,但我我无法想出一种方法来添加下个月的“下一个”/“上一个”链接......非常感谢任何帮助!
So I have currently used this http://davidwalsh.name/php-calendar as my calendar, but I am having trouble coming up with a way to add a 'next'/'previous' link to the next month... any help is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于绘制日历的功能是
您必须在下一个/上一个链接中提供
$month
和$year
,例如,此数据可在
$_GET 中使用
当点击这样的链接时。您不想要未经处理的数据,因此您可以在日历脚本顶部像这样获取它:过滤器功能将确保我们获得 1 到 12 之间的一个月以及 2010 到 2015 之间的一年(相应调整或删除选项,如您所见合身)。如果传递的数字不在该范围内(或者尚未单击任何链接),我们将得到它们的
false
,这意味着我们必须设置合理的默认值,例如这将使用有效值传递给脚本,或者,如果值无效,则将年份和/或月份设置为当前年份和/或月份。
现在绘制日历:
对于下一个/上一个链接,您可以手动检查月份是在 12 还是 1,然后相应地增加/减少年份,或者使用
DateTime
对象演示(略有删节)
另一种选择是将当前月份和年份存储在会话中,然后只有下一个/上一个链接没有年份和月份,而只是像 +1 和 -1 这样的东西来回移动。但是这样你就没有直接的方法可以跳转到某个月份。
这就是全部内容。
Since the function to draw the calender is
you have to supply
$month
and$year
in the next/previous links, e.g.This data is then available in
$_GET
when such a link is clicked. You dont want unsanitized data, so you fetch it like this on top of your calendar script:The filter function will make sure we get a month between 1 and 12 and a year between 2010 and 2015 (adjust accordingly or remove the options as you see fit). If the passed numbers are not in that range (or no link was clicked yet), we will get
false
for them, which means we will have to set sane defaults, e.g.This will either use the valid values passed to the script or, in case of invalid values, set the year and/or month to the current year and/or month.
Now draw the calendar:
For the next/previous link you can either manually check whether the month is at 12 or 1 and then increase/decrease the year accordingly or use a
DateTime
objectdemo (slightly abridged)
Another option would be to store the current month and year in a session and then just have next/previous links without year and month but rather just something like +1 and -1 to go back and forth. But then you have no direct way to jump to a certain month.
And that's all there is to it.