2012-07-11 1 views
-1

내 사이트의 경우 events.it로 캘린더를 작성하면 현재 달에는 정상적으로 작동합니다. 하지만 나는 페이지를 새로 고치지 않고 이전 및 다음 달을 이벤트로 연결하는 방법에 대해 혼란스러워합니다. 나는 아약스를 사용하고 싶지만 아무 생각도 없다. 어떤 도움도 환영합니다. 미리 감사드립니다. 내 코드 :페이지를 새로 고치지 않고 캘린더에서 이전 및 다음 달을 연결하는 방법

<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> 

답변

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); 
    } 

관련 문제