網站開發基本教學
  • Introduction
  • 基本元素
  • Nginx (伺服器)
    • Config 基本配置
    • Regular Expression 正規化
  • Codeigniter (程式語言框架)
    • Config
    • Controller
    • View
    • Model
      • Question
    • Helper
    • MVC
  • MySQL
Powered by GitBook
On this page

Was this helpful?

  1. Codeigniter (程式語言框架)

Controller

PreviousConfigNextView

Last updated 5 years ago

Was this helpful?

網站接口 (Boundary)

在routes裡的說明example.com/class/method/id/與下面比對

Welcome.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->load->view('welcome_message');
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

Controller.php

載入Boundary,產生instance

/**
 * CodeIgniter Application Controller Class
 *
 * This class object is the super class that every library in
 * CodeIgniter will be assigned to.
 *
 * @package        CodeIgniter
 * @subpackage    Libraries
 * @category    Libraries
 * @author        ExpressionEngine Dev Team
 * @link        http://codeigniter.com/user_guide/general/controllers.html
 */
class CI_Controller {

    private static $instance;

    /**
     * Constructor
     */
    public function __construct()
    {
        self::$instance =& $this;

        // Assign all the class objects that were instantiated by the
        // bootstrap file (CodeIgniter.php) to local class variables
        // so that CI can run as one big super object.
        foreach (is_loaded() as $var => $class)
        {
            $this->$var =& load_class($class);
        }

        $this->load =& load_class('Loader', 'core');

        $this->load->_base_classes =& is_loaded();

        $this->load->_ci_autoloader();

        log_message('debug', "Controller Class Initialized");

    }

    public static function &get_instance()
    {
        return self::$instance;
    }
}
// END Controller class

/* End of file Controller.php */
/* Location: ./system/core/Controller.php */

=&同等於 = new,php5以前為了object by reference

Deprecated features:

Assigning the return value of new by reference is now deprecated. Call-time pass-by-reference is now deprecated.

Example

example.com/index.php/products/shoes/sandals/123

<?php
class Products extends CI_Controller {

    public function shoes($sandals, $id)
    {
        echo $sandals;
        echo $id;
    }
}
?>