Welcome Guest, Not a member yet? Register   Sign In
AJAX Problems, where do I put the PHP part in CI?
#1

[eluser]Unknown[/eluser]
So I'm having an issue integrating my current setup into CI. I have just one index (view) and a controller that loads it. Now I created a mini event calendar that highlights days that has events going on. It displays fine in CI the problem is the way I'm displaying it. I'm not quite sure how to integrate it.

So I have a view with a div for the location of the calendar:

Code:
<div id="event_calendar">
     [removed]displayCalendar("","");[removed]
    </div>

This calls the displayCalendar function in event_calendar.js:

Code:
function displayCalendar(y, m)
{
var xmlhttp;
var year;
var month;
var currentTime = new Date()

if (window.XMLHttpRequest) {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp = new XMLHttpRequest();
} else {
  // code for IE6, IE5
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

xmlhttp.onreadystatechange=function()
{
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
   document.getElementById("event_calendar")[removed] = xmlhttp.responseText;
  }
}

if (y == "" || m == "") {
  year = currentTime.getFullYear()
  month = currentTime.getMonth() + 1
} else {
  year = y
  month = m
}

xmlhttp.open("GET","calendar.php?y=" + year + "&m=" + month, true);
xmlhttp.send();
}

This gets the entire calendar generated in calendar.php. Calendar.php deals with connecting to the database grabbing event days for the current month, setting the previous and next month arrows and the title. It has HTML at the bottom that generates the calendar using tables:

Code:
&lt;table border="1" cellpadding="0" cellspacing="0">
<tr class="cal_title">
  <td class="cal_left_arrow">
   <img src="images/left_arrow.jpg" width="9px" height="13px" />
  </td>
  <td class="cal_date" colspan="5">
   &lt;?php echo date('F', mktime(0,0,0,$month,1,$year)).'&nbsp;&nbsp;&nbsp;'.$year; ?&gt;
  </td>
  <td class="cal_right_arrow">
   <img src="images/right_arrow.jpg" width="9px" height="13px" />
  </td>
</tr>
<tr>
  <td class="cal_week_days">Sun</td>
  <td class="cal_week_days">Mon</td>
  <td class="cal_week_days">Tue</td>
  <td class="cal_week_days">Wed</td>
  <td class="cal_week_days">Thur</td>
  <td class="cal_week_days">Fri</td>
  <td class="cal_week_days">Sat</td>
</tr>

&lt;?php
foreach ($week as $key => $val) {
  echo "<tr>";
  for ($i=0;$i<7;$i++) {
   if ($year == $currYear && $month == $currMonth && $val[$i] == $currDay) {
    echo "<td class=\"cal_today\">$val[$i]</td>";
   } else {
    echo "<td class=\"cal_day\">$val[$i]</td>";
   }
  }
  echo "</tr>";
}
?&gt;
</table>

All this works and is pretty simple. The problem I have is currently calendar.php sits in my htdocs folder, I don't know where else to put it. Do I need to put it anywhere else? It seems like this should be a helper or library or something. The .js file that calls it makes it difficult to find a home for it. Can anyone point me in the right direction for how to handle this? Do I put the table in the view and use multiple AJAX requests / responses to fill in the values?




Theme © iAndrew 2016 - Forum software by © MyBB