-1

对于我的网站,我用 events.it 制作了一个日历。它在本月运行良好。但我对如何在不刷新页面的情况下将上个月和下个月的事件链接起来感到困惑。我想使用ajax,但我不知道。欢迎任何帮助。提前致谢。我的代码:

<h1><?php echo "<strong>".$current_month_text."</strong>";?></h1>
<a href="javascript:;" onclick="newCalender(<?php echo $previous_month;?>)">Previous</a>

<table cellspacing="0">
        <thead>
        <tr>
            <th>Sun</th>
            <th>Mon</th>
            <th>Tue</th>
            <th>Wed</th>
            <th>Thu</th>
            <th>Fri</th>
            <th>Sat</th>
        </tr>
        </thead>
        <tr>
            <?php

            for($i=0; $i< $total_rows; $i++)
            {
                for($j=0; $j<7;$j++)
                {
                    $day++;                 

                    if($day>0 && $day<=$total_days_of_current_month)
                    {
                        //YYYY-MM-DD date format
                        $date_form = "$current_year/$current_month/$day";

                        echo '<td';

                        //check if the date is today
                        if($date_form == $today)
                        {
                            echo ' id="today"';
                        }

                        //check if any event stored for the date
                        if(array_key_exists($day,$events))
                        {
                            //adding the date_has_event class to the <td> and close it
                            echo ' class="date_has_event"> '.$day;

                            //adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul>
                            echo '<div class="events"><ul>';

                            foreach ($events as $key=>$event){
                                if ($key == $day){
                                foreach ($event as $single){ 
                                    echo '<li>';                    
                                    echo anchor("events_detail/$single->url",'<span class="title">'.$single->event_title.'</span><span class="desc">'.character_limiter(strip_tags(stripslashes($single->description)),100).'</span>');                     
                                    echo '</li>'; 
                                } // end of for each $event
                                }

                            } // end of foreach $events


                            echo '</ul></div>';
                        } // end of if(array_key_exists...)

                        else 
                        {
                            //if there is not event on that date then just close the <td> tag
                            echo '> '.$day;
                        }
                        echo "</td>";
                    }
                    else 
                    {
                        //showing empty cells in the first and last row
                        echo '<td class="padding">&nbsp;</td>';
                    }
                }
                echo "</tr><tr>";
            }


            ?>
        </tr>

    </table>
4

1 回答 1

0

在日历的查看页面中:

<div class="calender">    
<span class="detail_button_left">&nbsp;</span>
    <a class="detail_bg" id="prev_button" href="<?php echo base_url() . "calender/". $previous_month;?>" >Previous</a>
<span class="detail_button_right">&nbsp;</span>
<div class="calender_next_btn">
    <span class="detail_button_left">&nbsp;</span>
        <a class="detail_bg" id="next_button" href="<?php echo base_url() . "calender/". $next_month; ?>" >Next</a>
    <span class="detail_button_right">&nbsp;</span>
</div> 
<h1><?php echo "<strong>".$current_month_text."</strong>";?></h1>
<div class="layout-grid">
    <table cellspacing="0">
        <thead>
            <tr>
                <th>Sun</th>
                <th>Mon</th>
                <th>Tue</th>
                <th>Wed</th>
                <th>Thu</th>
                <th>Fri</th>
                <th>Sat</th>
            </tr>
    </thead>
            <tr>
                <?php
                    for($i=0; $i< $total_rows; $i++)
                        {
                            for($j=0; $j<7;$j++)
                                {
                                    $day++;                 
                                    if($day>0 && $day<=$total_days_of_current_month)
                                    {
                                        //YYYY-MM-DD date format
                    $date_form = "$current_year/$current_month/$day";
                    echo '<td';
                    //check if the date is today
                    if($date_form == $today)
                    {
                                            echo ' id="today"';
                    }
                    //check if any event stored for the date
                    if(array_key_exists($day,$events))
                    {
                                            //adding the date_has_event class to the <td> and close it
                                            echo ' class="date_has_event"> '.$day;
                        //adding the eventTitle and eventContent wrapped inside <span> & <li> to <ul>
                                            echo '<div class="events"><ul>';
                       foreach ($events as $key=>$event)
                                            {
                                                if ($key == $day)
                                                {
                                                    foreach ($event as $single)
                                                    { 
                                                        echo '<li>';                    
                            echo anchor("events_detail/$single->url",
                                                                '<span class="title">'.$single->event_title.
                                                                '</span><span class="desc">'.character_limiter(strip_tags(stripslashes($single->description)),100).
                                                                '</span>');                     
                            echo '</li>'; 
                                                    } // end of for each $event
                        }
                                            } // end of foreach $events
                                            echo '</ul></div>';
                    } // end of if(array_key_exists...)
                    else 
                    {
                                            //if there is not event on that date then just close the <td> tag
                                            echo '> '.$day;
                    }
                    echo "</td>";
                                    }else{
                    //showing empty cells in the first and last row
                    echo '<td class="padding">&nbsp;</td>';
                                    }
                }
                echo "</tr><tr>";
                            }

            ?>
          </tr>
    </table>
</div>
</div>

在模型页面中:

function calender($slug=0)
    {
        $timeid = $this->uri->segment(3);
       if($timeid==0)
       {
           $time = time();
       }else{
           $time = $timeid;
       }
       if(!empty($slug)){
        $data['events']=$this->user_model->getEvents($slug);
        $today = date("Y/n/j", time());
    $data['today']= $today;
    $current_month = date("n", $slug);
    $data['current_month'] = $current_month;
    $current_year = date("Y", $slug);
    $data['current_year'] = $current_year;
    $current_month_text = date("F Y", $slug);
    $data['current_month_text'] = $current_month_text;
    $total_days_of_current_month = date("t", $slug);
    $data['total_days_of_current_month']= $total_days_of_current_month;
    $first_day_of_month = mktime(0,0,0,$current_month,1,$current_year);
    $data['first_day_of_month'] = $first_day_of_month;
    //geting Numeric representation of the day of the week for first day of the month. 0 (for Sunday) through 6 (for Saturday).
    $first_w_of_month = date("w", $first_day_of_month);
    $data['first_w_of_month'] = $first_w_of_month;
    //how many rows will be in the calendar to show the dates
    $total_rows = ceil(($total_days_of_current_month + $first_w_of_month)/7);
    $data['total_rows']= $total_rows;
    //trick to show empty cell in the first row if the month doesn't start from Sunday
    $day = -$first_w_of_month;
    $data['day']= $day;
    $next_month = mktime(0,0,0,$current_month+1,1,$current_year);
    $data['next_month']= $next_month;
    $next_month_text = date("F \'y", $next_month);
    $data['next_month_text']= $next_month_text;
    $previous_month = mktime(0,0,0,$current_month-1,1,$current_year);
    $data['previous_month']= $previous_month;
    $previous_month_text = date("F \'y", $previous_month);
    $data['previous_month_text']= $previous_month_text;
    $next_year = mktime(0,0,0,$current_month,1,$current_year+1);
    $data['next_year']= $next_year;
    $next_year_text = date("F \'y", $next_year);
    $data['next_year_text']= $next_year_text;
    $previous_year = mktime(0,0,0,$current_month,1,$current_year-1);
    $data['previous_year']=$previous_year;
    $previous_year_text = date("F \'y", $previous_year);
    $data['previous_year_text']= $previous_year_text;
       }
       else{
        $data['events']=$this->user_model->getEvents($time);
        $today = date("Y/n/j", time());
    $data['today']= $today;
    $current_month = date("n", $time);
    $data['current_month'] = $current_month;
    $current_year = date("Y", $time);
    $data['current_year'] = $current_year;
    $current_month_text = date("F Y", $time);
    $data['current_month_text'] = $current_month_text;
    $total_days_of_current_month = date("t", $time);
    $data['total_days_of_current_month']= $total_days_of_current_month;
    $first_day_of_month = mktime(0,0,0,$current_month,1,$current_year);
    $data['first_day_of_month'] = $first_day_of_month;
    //geting Numeric representation of the day of the week for first day of the month. 0 (for Sunday) through 6 (for Saturday).
    $first_w_of_month = date("w", $first_day_of_month);
    $data['first_w_of_month'] = $first_w_of_month;
    //how many rows will be in the calendar to show the dates
    $total_rows = ceil(($total_days_of_current_month + $first_w_of_month)/7);
    $data['total_rows']= $total_rows;
    //trick to show empty cell in the first row if the month doesn't start from Sunday
    $day = -$first_w_of_month;
    $data['day']= $day;
    $next_month = mktime(0,0,0,$current_month+1,1,$current_year);
    $data['next_month']= $next_month;
    $next_month_text = date("F \'y", $next_month);
    $data['next_month_text']= $next_month_text;
    $previous_month = mktime(0,0,0,$current_month-1,1,$current_year);
    $data['previous_month']= $previous_month;
    $previous_month_text = date("F \'y", $previous_month);
    $data['previous_month_text']= $previous_month_text;
    $next_year = mktime(0,0,0,$current_month,1,$current_year+1);
    $data['next_year']= $next_year;
    $next_year_text = date("F \'y", $next_year);
    $data['next_year_text']= $next_year_text;
    $previous_year = mktime(0,0,0,$current_month,1,$current_year-1);
    $data['previous_year']=$previous_year;
    $previous_year_text = date("F \'y", $previous_year);
    $data['previous_year_text']= $previous_year_text;
       }

        $this->load->view('calender', $data);
    }

其中 $slug 返回下一个/上一个的月份

于 2012-07-18T09:15:49.817 回答