是否可以调用CodeIgniter';使用php的s控制器?

是否可以调用CodeIgniter';使用php的s控制器?,php,codeigniter,Php,Codeigniter,是否可以使用php调用CodeIgniter的控制器 我正在考虑使用php调用控制器。我有一个全年的日历 <table style="margin-left:-50px;width:1300px;" class="table table-bordered"> <tr class="blue"> <th style="width:67px;">

是否可以使用php调用CodeIgniter的控制器

我正在考虑使用php调用控制器。我有一个全年的日历

<table style="margin-left:-50px;width:1300px;" class="table table-bordered">
                        <tr class="blue">
                            <th style="width:67px;">
                                <div style="position: absolute; margin-top: -5px;">
                                    <select style="width:auto;" name="years" onchange="submit();">
                                    <?php for($i=1;$i<=5;$i++): ?>
                                        <option value="<?php echo date('Y', strtotime('+'.$i.' year')); ?>" <?php echo ($dYear==date('Y', strtotime('+'.$i.' year'))?'selected':'');?>><?php echo date('Y', strtotime('+'.$i.' year')); ?></option>
                                       <?php endfor; ?>
                                    </select>
                                </div>      
                            </th>

                            <th>Su</th>
                            <th>Mo</th>
                            <th>Tu</th>
                            <th>We</th>
                            <th>Th</th>
                            <th>Fr</th>
                            <th>Sa</th>
                            <th>Su</th>
                            <th>Mo</th>
                            <th>Tu</th>
                            <th>We</th>
                            <th>Th</th>
                            <th>Fr</th>
                            <th>Sa</th>
                            <th>Su</th>
                            <th>Mo</th>
                            <th>Tu</th>
                            <th>We</th>
                            <th>Th</th>
                            <th>Fr</th>
                            <th>Sa</th>
                            <th>Su</th>
                            <th>Mo</th>
                            <th>Tu</th>
                            <th>We</th>
                            <th>Th</th>
                            <th>Fr</th>
                            <th>Sa</th>
                            <th>Su</th>
                            <th>Mo</th>
                            <th>Tu</th>
                            <th>We</th>
                            <th>Th</th>
                            <th>Fr</th>
                            <th>Sa</th>
                            <th>Su</th>
                            <th>Mo</th>

                        </tr>                                   
                        <?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<=$numberOfTdsToAdd;$i++) {
                            $tdString .= "<td></td>";
                            }
                            return $tdString;
                            }


                            for ($mC=1;$mC<=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 "<pre>".$daysInMonth."</pre>";
                            echo "<tr><td><div>".date("M",$currentDT)."</div></td>";


                            echo InsertBlankTd(FriendlyDayOfWeek(date("w",$currentDT))-0);

                            //for loop for inserting DAYS.
                            for ($i=1;$i<=$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 "<pre>".$aHoliday."</pre>";
                                        //$class = ($aHoliday == $rHoliday?"green-box":"");
                                        if ($aHoliday == $rHoliday){
                                            echo '<pre>'.$aHoliday . ' = ' .$nHoliday.'</pre>';
                                            $class = 'green-box';
                                        }
                                    }
                                }
                            }

                            //echo "<pre>".date("Y-n-j",$exactDT)."</pre>";
                            //if ($i==date("d")&&date("m",$currentDT)==date("m")) { $class="currentDay"; } else { $class = ""; }
                            echo "<td class=''>".$i.$class."</td>";
                            }

                            echo InsertBlankTd($dDaysOnPage - $daysInMonth - FriendlyDayOfWeek(date("w",$currentDT))-0);
                            echo "</tr>";
                            }
                            ?>
                    </table>

您希望在库或帮助器上调用特定函数。控制器的主要用途是充当路由器;这是因为它也是一个被许多人“误用”的类(我也这么做——我们都这么做)来包含许多相关函数&用$this->myfunction()调用它们


我不会在这里讨论这是否完全合适,但简单的回答是——使用库或助手函数来完成您所追求的类型;只在调用实际页面或api/ajax调用时调用控制器。

使用内置日历如何?您可以调用控制器,但我不理解mvc结构的要点,在控制器中,您只需调用库、模型等,这可以通过使用
$CI=&get_instance()轻松实现
@tomexsans,但codeigniter的内置日历仅显示月份。。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class attendance extends CI_Controller {



public function __construct()
{
    parent::__construct();
    $this->load->model('fill_in','fill');  //model fill in
    $this->load->model('mdl_employee','emp');
    $id = $this->session->userdata('id');        
}


public function index()
{ 
    $account = $this->session->userdata('account_type');
    if ($account == '3' || $account == '1')
    {
    $id = $this->session->userdata('id'); 
    $data['info'] = $this->emp->get_myinfo($id);
    $data['holiday'] = $this->emp->get_holidays();
    $data['employee_header_menus'] = $this->load->view('employee_header_menus', NULL, TRUE);
    $data['employee_header_logout'] = $this->load->view('employee_header_logout', $data, TRUE);
    $this->load->view('employee/attendance', $data);
    }
}
}
public function get_holidays()
{
    $this->db->select('*');
    $this->db->from('holidays');
    $query = $this->db->get();

    if($query->num_rows() > 0)
    {
        foreach ($query->result() as $row)
        {
            $data[] = array(
                    'description' => $row->description,
                    'date_stamp' => $row->date_stamp,
                    'repeats_annually' => $row->repeats_annually
                );
        }
    }
    else
    {
        $data = "";
    }
    return $data;
}