[PHP] Codeigniter 3 底層解析

Intro

CodeIgniter User Guide

bcit-ci/CodeIgniter


Router

Core: system/core/Router.php

Codeigniter core class執行裝載為$RTR

Uri中,Query String(Uri)的載入是在__construct()執行_set_routing()後,分別設定完成以下Properties:

  • class - Controller name
  • method - Action name
  • directory - Controller directory if exist

_set_routing() => _parse_routes() > _set_request() or _set_default_controller()

所以Router需裝載Uri並透過Uri取得segments注入設定。


Uri

Core: system/core/Uri.php

__construct()即會解析Uri(uri_string)至segments_set_uri_string()

Uri拿取方法uri_protocol預設就是使用:_parse_request_uri()


Database

Loader載入順序:

Loader -> DB(function) -> CI_DB_{driver}_driver extends ...

Database Object Inheritance:

$this->db > CI_DB_{driver}_driver > CI_DB > CI_DB_query_builder(Optional) > CI_DB_driver

實際query最後會由當前CI_DB_{driver}_driver呼叫_execute()調用個體實作。Builder有做到分離,但

Leave a Reply

Your email address will not be published. Required fields are marked *