Crazy 发表于 2010-3-9 10:40:36

求日历类扩展

要求是这样的:点击上一个月或下一个月链接的时候,号数有不同的链接,比如说3月份有12,22,25号是有活动的,就有链接,4月有11,15号是有活动的,也相应的标有链接,请教大侠应该如何扩展日历类,在线等。。。。。。

huboo82 发表于 2010-3-16 13:47:47

传数据到单元格增加数据到日历的单元格就要创建一个关联数组,在这个数组中索引是你想链接的天数value值包含你要传入的值.数组通过日历创建函数的第三个参数被传入. 参考下面这个例子:$date_time = time();
$year= ($this->uri->segment(2) == 'archive') ? $this->uri->segment(3) : date("Y", $date_time);
$month = ($this->uri->segment(2) == 'archive') ? $this->uri->segment(4) : date("m", $date_time);

$data = $this->get_calendar_data($year, $month);
比如返回的data如下
$data = array(
               3=> 'http://example.com/news/article/2006/03/',
               7=> 'http://example.com/news/article/2006/07/',
               13 => 'http://example.com/news/article/2006/13/',
               26 => 'http://example.com/news/article/2006/26/'
             );$this->load->library('calendar');

echo $this->calendar->generate($year, $month, $data);使用上面的例子,天数3,7,13和26将变成链接指向你提供的URLs.

Crazy 发表于 2010-3-17 10:54:28

请问怎样才能让$data = $this->get_calendar_data($year, $month);的$data返回的是这个样子的
$data = array(
               3=> 'http://example.com/news/article/2006/03/',
               7=> 'http://example.com/news/article/2006/07/',
               13 => 'http://example.com/news/article/2006/13/',
               26 => 'http://example.com/news/article/2006/26/'
             );
请教这个方法$this->get_calendar_data($year, $month)是如何写的能举个例子吗    非常感谢

huboo82 发表于 2010-3-17 11:58:08

/**
* 返回日历上的存档链接
* @access public
* @param integer $year
* @param integer $month
* @return array
*/
public function get_calendar_data($year, $month)
{

$time_start = mktime(0, 0, 0, $month, 1, $year);

$time_end = mktime(0, 0, 0, $month+1, 1, $year);

$this->db->select('create_date');

$this->db->from('news');

$this->db->where('create_date >=', $time_start);

$this->db->where('create_date <', $time_end);

$cal_res = $this->db->get()->result_array();


$cal_url = array();

foreach(array_keys($cal_res) as $key)

{

$cal_date = $cal_res[$key]['create_date'];

$cal_url = site_url('news/article/'.date('Y/n/', $cal_date));

}

return $cal_url;
}

Crazy 发表于 2010-3-17 15:33:43

本帖最后由 Crazy 于 2010-3-30 01:36 编辑

问题已经解决,非常感谢楼上的大哥。:handshake

流浪的乞丐 发表于 2011-11-29 15:32:17

这个帖子学到东西了,thx:lol

chenhan 发表于 2011-12-14 16:20:03

学习了

栤葑の噯 发表于 2013-1-30 13:51:39

:lol学习了

smallhe 发表于 2013-1-31 20:54:50

标记一下!

kuailewang 发表于 2013-5-8 12:27:34

huboo82 发表于 2010-3-16 13:47 static/image/common/back.gif
传数据到单元格增加数据到日历的单元格就要创建一个关联数组,在这个数组中索引是你想链接的天数value值包含 ...

好,很好!支持:curse:
页: [1]
查看完整版本: 求日历类扩展