使用数组在codeIgniter Calendar类 [英] Using arrays with the Calendar class in CodeIgniter

查看:166
本文介绍了使用数组在codeIgniter Calendar类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建我的日历应用程序相当复杂的阵列。它应该包含日期,与天,类型和事件,如果有的话的名称。我得到尽可能创造这样的:

I'm trying to create a rather complex array for my calendar application. It's supposed to contain dates, with the name of the day, the 'type' and the events, if any. I got as far as creating this:

[dates] {
        [22] {
             [day] => [Friday]
             [type] => [weekday]                              
        }
        [23] {
             [day] => [Saturday]
             [type] => [Weekend]
        }
        [24] {
             [day] => [Sunday]
             [type] => [Weekend]
        }
}

现在我想添加一个名为事件的另一个关键。我要为每一天的事件添加到阵列..所以我能得到​​这样的:

Now I would like to add another key called 'events'. I want to add the events for each day to the array.. So I could get something like:

        [24] {
             [day] => [Sunday]
             [type] => [Weekend]
             [events] {
                      [1] {
                          [title] => [test event]
                          [description] => [my event]
                          [date] => [24-04-2011]
                      }
                      [2] {
                          [title] => [test event 2]
                          [description] => [my second event]
                          [date] => [24-04-2011]
                      }
              }

不知道这是有道理的。

Not sure if this makes sense.

我用这个code创建的第一个例子:

I created the first example using this code:

        for($i = 1; $i <= $data['days_in_curr_month']; $i++)
    {
        $day_info = $this->get_day_info($i, $data['current_month'], $data['current_year']);

        $dates[$i]['name'] = $day_info['day_name'];
        $dates[$i]['type'] = $day_info['day_type'];
    }

    return $dates;

我当时就想抓住做事件信息:

I then wanted to grab the event info by doing:

$ event_info = $这个 - &GT; get_event_info($ I,$数据['current_month'],$数据['CURRENT_YEAR']);

在同一个for循环。

我get_event_info方法是这样的:

My get_event_info method looks like this:

    public function get_event_info($day, $month, $year)
{
    $date = $year . "-" . $month . "-" . $day;
    $this->db->where('date', $date);
    $this->db->where('user_id', '1');   
    $query = $this->db->get('tblEvents');

    $event_info = array();

    foreach($query->result() as $row)
    {
        $event_info['events'][$row->id]['title'] = $row->title;
        $event_info['events'][$row->id]['description'] = $row->description;
    }

    return $event_info;

}

据输出数组是这样的:

It outputs arrays like this:

Array ( [events] => Array ( [1] => Array ( [title] => Project 2 [description] => Test: Project 2 ) [2] => Array ( [title] => Illustrator [description] => Test: Illustrator 2 ) ) )

现在,我回到从 get_events_info 的$ event_info到 create_dates_list 方法,但我不知道怎么样我会去加入我的事件阵列到$日期排列。

Now, I return the $event_info from get_events_info to the create_dates_list method, but I'm not sure how I would go about adding my event arrays to the $dates array.

该get_event_info获得每个日期的事件(1 - 月 - 结束)。那么我想添加那些我$日期排列在我的第二个例子上面列出的格式。

The get_event_info gets the events for each date (1 - end of month-). I then want to add those to my $dates array in the format listed above in my second example.

我感到困惑的原因,这些都是相当复杂的阵列。先谢谢了。

I'm confused cause these are rather complex arrays. Thanks in advance.

推荐答案

我认为你需要做的是(例如):

I think all you need to do is (for example):

 $append_events = get_event_info($day, $month, $year);
 $array['dates']['1']['event'] = $append_events['events'];

然后你就可以访问你的元素:

Then you can access your elements:

 $array['dates']['1']['event'][$id]['title']    
 $array['dates']['1']['event'][$id]['description']    

这篇关于使用数组在codeIgniter Calendar类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆