title: Is it possible to call CodeIgniter's controller using php?
body: <p>Is it possible to call CodeIgniter's controller using php?</p>
  
  <p>I'm thinking of calling the controller using php. I have a display all year calendar.</p>
  
  <pre><code>&lt;table style="margin-left:-50px;width:1300px;" class="table table-bordered"&gt;
                          &lt;tr class="blue"&gt;
                              &lt;th style="width:67px;"&gt;
                                  &lt;div style="position: absolute; margin-top: -5px;"&gt;
                                      &lt;select style="width:auto;" name="years" onchange="submit();"&gt;
                                      &lt;?php for($i=1;$i&lt;=5;$i++): ?&gt;
                                          &lt;option value="&lt;?php echo date('Y', strtotime('+'.$i.' year')); ?&gt;" &lt;?php echo ($dYear==date('Y', strtotime('+'.$i.' year'))?'selected':'');?&gt;&gt;&lt;?php echo date('Y', strtotime('+'.$i.' year')); ?&gt;&lt;/option&gt;
                                         &lt;?php endfor; ?&gt;
                                      &lt;/select&gt;
                                  &lt;/div&gt;      
                              &lt;/th&gt;
  
                              &lt;th&gt;Su&lt;/th&gt;
                              &lt;th&gt;Mo&lt;/th&gt;
                              &lt;th&gt;Tu&lt;/th&gt;
                              &lt;th&gt;We&lt;/th&gt;
                              &lt;th&gt;Th&lt;/th&gt;
                              &lt;th&gt;Fr&lt;/th&gt;
                              &lt;th&gt;Sa&lt;/th&gt;
                              &lt;th&gt;Su&lt;/th&gt;
                              &lt;th&gt;Mo&lt;/th&gt;
                              &lt;th&gt;Tu&lt;/th&gt;
                              &lt;th&gt;We&lt;/th&gt;
                              &lt;th&gt;Th&lt;/th&gt;
                              &lt;th&gt;Fr&lt;/th&gt;
                              &lt;th&gt;Sa&lt;/th&gt;
                              &lt;th&gt;Su&lt;/th&gt;
                              &lt;th&gt;Mo&lt;/th&gt;
                              &lt;th&gt;Tu&lt;/th&gt;
                              &lt;th&gt;We&lt;/th&gt;
                              &lt;th&gt;Th&lt;/th&gt;
                              &lt;th&gt;Fr&lt;/th&gt;
                              &lt;th&gt;Sa&lt;/th&gt;
                              &lt;th&gt;Su&lt;/th&gt;
                              &lt;th&gt;Mo&lt;/th&gt;
                              &lt;th&gt;Tu&lt;/th&gt;
                              &lt;th&gt;We&lt;/th&gt;
                              &lt;th&gt;Th&lt;/th&gt;
                              &lt;th&gt;Fr&lt;/th&gt;
                              &lt;th&gt;Sa&lt;/th&gt;
                              &lt;th&gt;Su&lt;/th&gt;
                              &lt;th&gt;Mo&lt;/th&gt;
                              &lt;th&gt;Tu&lt;/th&gt;
                              &lt;th&gt;We&lt;/th&gt;
                              &lt;th&gt;Th&lt;/th&gt;
                              &lt;th&gt;Fr&lt;/th&gt;
                              &lt;th&gt;Sa&lt;/th&gt;
                              &lt;th&gt;Su&lt;/th&gt;
                              &lt;th&gt;Mo&lt;/th&gt;
  
                          &lt;/tr&gt;                                   
                          &lt;?php
                              function FriendlyDayOfWeek($dayNum) {
                              // converts the sunday to 7
                              // This function can be removed in php 5 by - date("N"),
                              // just remove function calls below and replace by swapping date("w" for date("N"
                              if ($dayNum == 0){ return 0; } else { return $dayNum; }
                              }
  
                              //inserting blank TDs
                              function InsertBlankTd($numberOfTdsToAdd) {
                              for($i=1;$i&lt;=$numberOfTdsToAdd;$i++) {
                              $tdString .= "&lt;td&gt;&lt;/td&gt;";
                              }
                              return $tdString;
                              }
  
  
                              for ($mC=1;$mC&lt;=12;$mC++) {
                              //for loop for inserting MONTHS
                              /*
                               * $mC = MONTH
                               * $dDay = DAY
                               * $dYear = YEAR
                               */
                              $currentDT = mktime(0,0,0,$mC,$dDay,$dYear);
                              $daysInMonth = date("t",$currentDT);
                              $dMonth = date("n",$currentDT);
                              //echo "&lt;pre&gt;".$daysInMonth."&lt;/pre&gt;";
                              echo "&lt;tr&gt;&lt;td&gt;&lt;div&gt;".date("M",$currentDT)."&lt;/div&gt;&lt;/td&gt;";
  
  
                              echo InsertBlankTd(FriendlyDayOfWeek(date("w",$currentDT))-0);
  
                              //for loop for inserting DAYS.
                              for ($i=1;$i&lt;=$daysInMonth;$i++) {
                              $exactDT = mktime(0,0,0,$mC,$i,$dYear);
                              $rHoliday = date("n-j",$exactDT); // repeating holidays
                              $nHoliday = date("Y-n-j",$exactDT); //non-repeating holidays
  //check if holiday.
                              if ($holiday!=""){
                                  foreach($holiday as $row){
                                      if ($row['repeats_annually'] == "Yes")
                                      {
                                          $h = explode("-", $row['date_stamp']); 
                                          $aHoliday = $h[1]."-".$h[2]; //annual holidays
                                          //echo "&lt;pre&gt;".$aHoliday."&lt;/pre&gt;";
                                          //$class = ($aHoliday == $rHoliday?"green-box":"");
                                          if ($aHoliday == $rHoliday){
                                              echo '&lt;pre&gt;'.$aHoliday . ' = ' .$nHoliday.'&lt;/pre&gt;';
                                              $class = 'green-box';
                                          }
                                      }
                                  }
                              }
  
                              //echo "&lt;pre&gt;".date("Y-n-j",$exactDT)."&lt;/pre&gt;";
                              //if ($i==date("d")&amp;&amp;date("m",$currentDT)==date("m")) { $class="currentDay"; } else { $class = ""; }
                              echo "&lt;td class=''&gt;".$i.$class."&lt;/td&gt;";
                              }
  
                              echo InsertBlankTd($dDaysOnPage - $daysInMonth - FriendlyDayOfWeek(date("w",$currentDT))-0);
                              echo "&lt;/tr&gt;";
                              }
                              ?&gt;
                      &lt;/table&gt;
  </code></pre>
  
  <p>now you'll see on my comment "//for loop for inserting DAYS.", you will see the another comment '//check if holiday.' in which i will put a class on that td and will make it color green if it's holiday. the problem is I think my algorithm is wrong on that. so i'm thinking that i will delete that foreach on the $holiday. and will just call the controller function in which every "day" will be compared and check if it's holiday instead of using foreach if it's possible to call the controller using php. but is there any other way to do it more simpler? or if not. it's also ok. </p>
  
  <p>here's the controller</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class attendance extends CI_Controller {
  
  
  
  public function __construct()
  {
      parent::__construct();
      $this-&gt;load-&gt;model('fill_in','fill');  //model fill in
      $this-&gt;load-&gt;model('mdl_employee','emp');
      $id = $this-&gt;session-&gt;userdata('id');        
  }
  
  
  public function index()
  { 
      $account = $this-&gt;session-&gt;userdata('account_type');
      if ($account == '3' || $account == '1')
      {
      $id = $this-&gt;session-&gt;userdata('id'); 
      $data['info'] = $this-&gt;emp-&gt;get_myinfo($id);
      $data['holiday'] = $this-&gt;emp-&gt;get_holidays();
      $data['employee_header_menus'] = $this-&gt;load-&gt;view('employee_header_menus', NULL, TRUE);
      $data['employee_header_logout'] = $this-&gt;load-&gt;view('employee_header_logout', $data, TRUE);
      $this-&gt;load-&gt;view('employee/attendance', $data);
      }
  }
  }
  </code></pre>
  
  <p>and the model for $data['holiday']</p>
  
  <pre><code>public function get_holidays()
  {
      $this-&gt;db-&gt;select('*');
      $this-&gt;db-&gt;from('holidays');
      $query = $this-&gt;db-&gt;get();
  
      if($query-&gt;num_rows() &gt; 0)
      {
          foreach ($query-&gt;result() as $row)
          {
              $data[] = array(
                      'description' =&gt; $row-&gt;description,
                      'date_stamp' =&gt; $row-&gt;date_stamp,
                      'repeats_annually' =&gt; $row-&gt;repeats_annually
                  );
          }
      }
      else
      {
          $data = "";
      }
      return $data;
  }
  </code></pre>