首页 > 其他分享 >ci框架

ci框架

时间:2024-02-23 14:00:47浏览次数:19  
标签:ci name 框架 SERVER directory php class

1. ci背景

ci在这里是一个php框架,官网地址: https://codeigniter.org.cn/

https://codeigniter.org.cn/

2. 特点

2.1 键值对object管理

load_class管理对象加载,负责jd生成加载快的对象,存入在键值对中,方便复用。

 1     /**
 2      * Class registry
 3      *
 4      * This function acts as a singleton. If the requested class does not
 5      * exist it is instantiated and set to a static variable. If it has
 6      * previously been instantiated the variable is returned.
 7      *
 8      * @param    string    the class name being requested
 9      * @param    string    the directory where the class should be found
10      * @param    mixed    an optional argument to pass to the class constructor
11      * @return    object
12      */
13     function &load_class($class, $directory = 'libraries', $param = NULL)
14     {
15         static $_classes = array();
16 
17         // Does the class exist? If so, we're done...
18         if (isset($_classes[$class]))
19         {
20             return $_classes[$class];
21         }
22 
23         $name = FALSE;
24 
25         // Look for the class first in the local application/libraries folder
26         // then in the native system/libraries folder
27         foreach (array(APPPATH, BASEPATH) as $path)
28         {
29             if (file_exists($path.$directory.'/'.$class.'.php'))
30             {
31                 $name = 'CI_'.$class;
32 
33                 if (class_exists($name, FALSE) === FALSE)
34                 {
35                     require_once($path.$directory.'/'.$class.'.php');
36                 }
37 
38                 break;
39             }
40         }
41 
42         // Is the request a class extension? If so we load it too
43         if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
44         {
45             $name = config_item('subclass_prefix').$class;
46 
47             if (class_exists($name, FALSE) === FALSE)
48             {
49                 require_once(APPPATH.$directory.'/'.$name.'.php');
50             }
51         }
52 
53         // Did we find the class?
54         if ($name === FALSE)
55         {
56             // Note: We use exit() rather than show_error() in order to avoid a
57             // self-referencing loop with the Exceptions class
58             set_status_header(503);
59             echo 'Unable to locate the specified class: '.$class.'.php';
60             exit(5); // EXIT_UNK_CLASS
61         }
62 
63         // Keep track of what we just loaded
64         is_loaded($class);
65 
66         $_classes[$class] = isset($param)
67             ? new $name($param)
68             : new $name();
69         return $_classes[$class];
70     }
View Code

基于这个特点,多次load_class会加载出在其它地方操作过的对象···

3. 自测

以version = 3.1.11为例

3.1 post/get/delete等等自测举例

若在本地进行test验证,需要准备相关全局变量: $_SERVER, $routing

其中$routing, 为ci框架的全局变量

下面是发起一个接口的请求,在cli中实现,需要注意的是在arena项目中,ci框架的入口文件,需要专门编辑出来一个cli文件,可以考虑直接copy所属app运行目录的index.php文件。

 1 /**
 2  * @brief test func
 3  */
 4 //入参准备
 5 $_POST = [
 6     "a" => b,
 7 ];
 8 //地址准备
 9 $_SERVER['CI_ENV'] = "local";
10 $_SERVER['REQUEST_METHOD'] = "POST";
11 $routing["directory"] = "api";
12 $routing["controller"] = "test";
13 $routing["function"] = "func";

准备完这些后,多数api已经能足够完成自测。

3.2 接口入参注入自测

而ci框架,还支持一种关于入参注入的功能。

举例如下

1 class testN {
2   public function coinInfinite($id) {
3     var_dump($id);
4   }
5 }

即在函数的api层面,支持params的设定,而非通过php兼容的入参协议获得。

通过排查,ci框架的核心类:

arena/src/system/core/URI.php

会操作 $_SERVER全局变量中的元素argv

arena/src/system/core/Router.php

依据ci键值对object的操作,将CI_URI对象,复用在CI_Router中。

CI_Router->_set_routing()由该函数实现

 

所以根据于此,示例如下

1 /**
2  * @brief test api func
3  */
4 
5 //地址准备
6 $_SERVER['CI_ENV'] = "local";
7 $_SERVER['REQUEST_METHOD'] = "GET";
8 array_push($_SERVER['argv'], "api/test/func/123");

argv新插入的数组元素中的123,就是注入到举例函数: coinInfinite中的入参 $id

标签:ci,name,框架,SERVER,directory,php,class
From: https://www.cnblogs.com/supermarx/p/18029357

相关文章

  • 开源:Taurus.DistributedLock 分布式锁框架,支持 .Net 和 .Net Core 双系列版本
    前言:在经过漫长的技术沉淀,终于又为.Net及.NetCore的微服务系列框架贡献当中的一个重要组件。Taurus.DistributedLockisadistributedlockfor.netor.netcore.【支持:Redis、MemCache、Database、Local、File五类锁】1、开源地址:https://github.com/cyq1162/Taurus......
  • 在 ESXi 上运行 Cisco Nexus 9000v (NX-OS 10)
    在ESXi上运行CiscoNexus9000v(NX-OS10)在VMwarevSphere中部署CiscoNexus9000v(NX-OS10)请访问原文链接:https://sysin.org/blog/run-nxos-on-esxi/,查看最新版。原创作品,转载请保留出处。作者主页:sysin.orgNexus9000v概述CiscoNexus9000v是虚拟化的Nexus......
  • SciTech-Mathmatics-FourierSeries: Time Domain and Frequency Domain
    TimeDomainandFrequencyDomainFrequencydomain:measuredbySpectrumAnalysiszerTellsushowproperties(amplitudes)changeoverfrequencies:TimeDomain:measuredbyOscilloscopeTellsushowproperties(suchasAmplitude(Power),Phase,andsoon)......
  • 软件无线电处理平台设计方案:330-基于FMC接口的Kintex-7 XC7K325T PCIeX4 3U PXIe接口
    一、板卡概述   本板卡基于Xilinx公司的FPGAXC7K325T-2FFG900 芯片,pin_to_pin兼容FPGAXC7K410T-2FFG900 ,支持PCIeX8、64bit DDR3容量2GByte,HPC的FMC连接器,板卡支持PXIE标准协议,其中XJ3标准高速差分接口,支持PCIeX 2。软件具有windows,Linux驱动。 二、功能和技术指标......
  • System.net.Mail only supports explicit SSL
    System.net.Mailsometimesfailstobesentunderthesslsmtpserver.Afterawhile,itseemslikethisistheproblem.Sendingmailusingsystem.net.MailwithSSLwillfail:System.net.NetworkcredentialAcred=NewSystem.net.Networkcredential("M......
  • 洛谷 P6785 [COCI2013-2014#6] KRUŽNICE
    COCI的题。显然,手模样例发现答案分为以下几个贡献:所有圆外面的那个大平面,贡献为\(1\)。每个圆至少被分成一部分,贡献为\(n\)。如果有一个圆被“拦腰截断了”,即整条直径上都被更小的圆填满了,就额外对答案贡献加\(1\),这也是我们所求部分。暴力跳set遇事不决,先打暴力;不加......
  • 运行 decision transformer 遇到的问题
    简介本质上强化学习也是为了预测下一个action,那能否借用大模型的方法来实现next-action的预测。业界有多篇借用大模型的方法(transfomer)来实现这个目的。伯克利的这篇算是最为彻底和简洁。https://sites.google.com/berkeley.edu/decision-transformer transfomer官方网站......
  • EfficientNet环境搭建&网络修改
    引子在深度学习CV领域,最初2012年突破的就是图像分类,发展这么多年,基本上已经没有什么进展了。此篇作为之前EfficientNet挽留过的总结,现在整理下,OK,让我们开始吧。一、EfficientNet安装1、pytorch版本网址:https://github.com/lukemelas/EfficientNet-PyTorch2、pipinstalleffic......
  • scrapy框架的安装
    第一步:安装scrapy模块pipinstallscrapy第二步:在需要创建的文件夹内打开cmd窗口输入scrapystartprojectmyfirstscrapy会看到下面的命令:Youcanstartyourfirstspiderwith:cdmyfirstscrapyscrapygenspiderexampleexample.com第三步:根据命令提示输......
  • nginx与php pathinfo(TP5框架适用)
    最近在试用fastadmin这一个框架,是由tp5进行二开后的一款框架。fastadmin里面有个代码,要获取pathinfo否则会重定向到登录页,而默认的nginx配置获取的pathinfo一直为空,就导致无法正常进入后台。通过查找资料后,发现pathinfo是php的产物,与nginx无关。如果要让nginx把pathinfo环境变量......