单字母函数D、F、S、C、L、A、I 他们都在ThinkPHP核心的ThinkPHP/Mode/Api/functions.php这个文件中定义.
下面我分别说明一下他们的功能:
D() 加载Model类
M() 加载Model类
A() 加载Action类
L() 获取语言定义
C() 获取配置值 用法就是 C("这里填写在配置文件里数组的下标")
S() 全局缓存配置 用法S(“这里相当于一个唯一的标识”)
F() 快速文件数据读取和保存 针对简单类型数据 字符串、数组
I() 快速创建一个对象实例
此处附带:ThinkPHP内置所有函数的原型定义
<span> 1</span> <?<span>php </span><span> 2</span> <span> 3</span> <span>/*</span><span>* </span><span> 4</span> <span> * Think API模式函数库 </span><span> 5</span> <span>*/</span> <span> 6</span> <span> 7</span> <span>/*</span><span>* </span><span> 8</span> <span> * 获取和设置配置参数 支持批量定义 </span><span> 9</span> <span> * @param string|array $name 配置变量 </span><span> 10</span> <span> * @param mixed $value 配置值 </span><span> 11</span> <span> * @param mixed $default 默认值 </span><span> 12</span> <span> * @return mixed </span><span> 13</span> <span>*/</span> <span> 14</span> <span>function</span> C(<span>$name</span>=<span>null</span>, <span>$value</span>=<span>null</span>,<span>$default</span>=<span>null</span><span>) {} </span><span> 15</span> <span> 16</span> <span>/*</span><span>* </span><span> 17</span> <span> * 加载配置文件 支持格式转换 仅支持一级配置 </span><span> 18</span> <span> * @param string $file 配置文件名 </span><span> 19</span> <span> * @param string $parse 配置解析方法 有些格式需要用户自己解析 </span><span> 20</span> <span> * @return void </span><span> 21</span> <span>*/</span> <span> 22</span> <span>function</span> load_config(<span>$file</span>,<span>$parse</span>=<span>CONF_PARSE) {} </span><span> 23</span> <span> 24</span> <span>/*</span><span>* </span><span> 25</span> <span> * 抛出异常处理 </span><span> 26</span> <span> * @param string $msg 异常消息 </span><span> 27</span> <span> * @param integer $code 异常代码 默认为0 </span><span> 28</span> <span> * @return void </span><span> 29</span> <span>*/</span> <span> 30</span> <span>function</span> E(<span>$msg</span>, <span>$code</span>=0<span>) {} </span><span> 31</span> <span> 32</span> <span>/*</span><span>* </span><span> 33</span> <span> * 记录和统计时间(微秒)和内存使用情况 </span><span> 34</span> <span> * 使用方法: </span><span> 35</span> <span> * <code> </span><span> 36</span> <span> * G('begin'); // 记录开始标记位 </span><span> 37</span> <span> * // ... 区间运行代码 </span><span> 38</span> <span> * G('end'); // 记录结束标签位 </span><span> 39</span> <span> * echo G('begin','end',6); // 统计区间运行时间 精确到小数后6位 </span><span> 40</span> <span> * echo G('begin','end','m'); // 统计区间内存使用情况 </span><span> 41</span> <span> * 如果end标记位没有定义,则会自动以当前作为标记位 </span><span> 42</span> <span> * 其中统计内存使用需要 MEMORY_LIMIT_ON 常量为true才有效 </span><span> 43</span> <span> * </code> </span><span> 44</span> <span> * @param string $start 开始标签 </span><span> 45</span> <span> * @param string $end 结束标签 </span><span> 46</span> <span> * @param integer|string $dec 小数位或者m </span><span> 47</span> <span> * @return mixed </span><span> 48</span> <span>*/</span> <span> 49</span> <span>function</span> G(<span>$start</span>,<span>$end</span>='',<span>$dec</span>=4<span>) {} </span><span> 50</span> <span> 51</span> <span>/*</span><span>* </span><span> 52</span> <span> * 获取和设置语言定义(不区分大小写) </span><span> 53</span> <span> * @param string|array $name 语言变量 </span><span> 54</span> <span> * @param string $value 语言值 </span><span> 55</span> <span> * @return mixed </span><span> 56</span> <span>*/</span> <span> 57</span> <span>function</span> L(<span>$name</span>=<span>null</span>, <span>$value</span>=<span>null</span><span>) {} </span><span> 58</span> <span> 59</span> <span>/*</span><span>* </span><span> 60</span> <span> * 添加和获取页面Trace记录 </span><span> 61</span> <span> * @param string $value 变量 </span><span> 62</span> <span> * @param string $label 标签 </span><span> 63</span> <span> * @param string $level 日志级别 </span><span> 64</span> <span> * @param boolean $record 是否记录日志 </span><span> 65</span> <span> * @return void </span><span> 66</span> <span>*/</span> <span> 67</span> <span>function</span> trace(<span>$value</span>='[think]',<span>$label</span>='',<span>$level</span>='DEBUG',<span>$record</span>=<span>false</span><span>) {} </span><span> 68</span> <span> 69</span> <span>/*</span><span>* </span><span> 70</span> <span> * 编译文件 </span><span> 71</span> <span> * @param string $filename 文件名 </span><span> 72</span> <span> * @return string </span><span> 73</span> <span>*/</span> <span> 74</span> <span>function</span> compile(<span>$filename</span><span>) {} </span><span> 75</span> <span> 76</span> <span>/*</span><span>* </span><span> 77</span> <span> * 获取输入参数 支持过滤和默认值 </span><span> 78</span> <span> * 使用方法: </span><span> 79</span> <span> * <code> </span><span> 80</span> <span> * I('id',0); 获取id参数 自动判断get或者post </span><span> 81</span> <span> * I('post.name','','htmlspecialchars'); 获取$_POST['name'] </span><span> 82</span> <span> * I('get.'); 获取$_GET </span><span> 83</span> <span> * </code> </span><span> 84</span> <span> * @param string $name 变量的名称 支持指定类型 </span><span> 85</span> <span> * @param mixed $default 不存在的时候默认值 </span><span> 86</span> <span> * @param mixed $filter 参数过滤方法 </span><span> 87</span> <span> * @return mixed </span><span> 88</span> <span>*/</span> <span> 89</span> <span>function</span> I(<span>$name</span>,<span>$default</span>='',<span>$filter</span>=<span>null</span><span>) {} </span><span> 90</span> <span> 91</span> <span>/*</span><span>* </span><span> 92</span> <span> * 设置和获取统计数据 </span><span> 93</span> <span> * 使用方法: </span><span> 94</span> <span> * <code> </span><span> 95</span> <span> * N('db',1); // 记录数据库操作次数 </span><span> 96</span> <span> * N('read',1); // 记录读取次数 </span><span> 97</span> <span> * echo N('db'); // 获取当前页面数据库的所有操作次数 </span><span> 98</span> <span> * echo N('read'); // 获取当前页面读取次数 </span><span> 99</span> <span> * </code> </span><span>100</span> <span> * @param string $key 标识位置 </span><span>101</span> <span> * @param integer $step 步进值 </span><span>102</span> <span> * @return mixed </span><span>103</span> <span>*/</span> <span>104</span> <span>function</span> N(<span>$key</span>, <span>$step</span>=0,<span>$save</span>=<span>false</span><span>) {} </span><span>105</span> <span>106</span> <span>/*</span><span>* </span><span>107</span> <span> * 字符串命名风格转换 </span><span>108</span> <span> * type 0 将Java风格转换为C的风格 1 将C风格转换为Java的风格 </span><span>109</span> <span> * @param string $name 字符串 </span><span>110</span> <span> * @param integer $type 转换类型 </span><span>111</span> <span> * @return string </span><span>112</span> <span>*/</span> <span>113</span> <span>function</span> parse_name(<span>$name</span>, <span>$type</span>=0<span>) {} </span><span>114</span> <span>115</span> <span>/*</span><span>* </span><span>116</span> <span> * 优化的require_once </span><span>117</span> <span> * @param string $filename 文件地址 </span><span>118</span> <span> * @return boolean </span><span>119</span> <span>*/</span> <span>120</span> <span>function</span> require_cache(<span>$filename</span><span>) {} </span><span>121</span> <span>122</span> <span>/*</span><span>* </span><span>123</span> <span> * 区分大小写的文件存在判断 </span><span>124</span> <span> * @param string $filename 文件地址 </span><span>125</span> <span> * @return boolean </span><span>126</span> <span>*/</span> <span>127</span> <span>function</span> file_exists_case(<span>$filename</span><span>) {} </span><span>128</span> <span>129</span> <span>/*</span><span>* </span><span>130</span> <span> * 导入所需的类库 同java的Import 本函数有缓存功能 </span><span>131</span> <span> * @param string $class 类库命名空间字符串 </span><span>132</span> <span> * @param string $baseUrl 起始路径 </span><span>133</span> <span> * @param string $ext 导入的文件扩展名 </span><span>134</span> <span> * @return boolean </span><span>135</span> <span>*/</span> <span>136</span> <span>function</span> import(<span>$class</span>, <span>$baseUrl</span> = '', <span>$ext</span>=<span>EXT) {} </span><span>137</span> <span>138</span> <span>/*</span><span>* </span><span>139</span> <span> * 基于命名空间方式导入函数库 </span><span>140</span> <span> * load('@.Util.Array') </span><span>141</span> <span> * @param string $name 函数库命名空间字符串 </span><span>142</span> <span> * @param string $baseUrl 起始路径 </span><span>143</span> <span> * @param string $ext 导入的文件扩展名 </span><span>144</span> <span> * @return void </span><span>145</span> <span>*/</span> <span>146</span> <span>function</span> load(<span>$name</span>, <span>$baseUrl</span>='', <span>$ext</span>='.php'<span>) {} </span><span>147</span> <span>148</span> <span>/*</span><span>* </span><span>149</span> <span> * 快速导入第三方框架类库 所有第三方框架的类库文件统一放到 系统的Vendor目录下面 </span><span>150</span> <span> * @param string $class 类库 </span><span>151</span> <span> * @param string $baseUrl 基础目录 </span><span>152</span> <span> * @param string $ext 类库后缀 </span><span>153</span> <span> * @return boolean </span><span>154</span> <span>*/</span> <span>155</span> <span>function</span> vendor(<span>$class</span>, <span>$baseUrl</span> = '', <span>$ext</span>='.php'<span>) {} </span><span>156</span> <span>157</span> <span>/*</span><span>* </span><span>158</span> <span> * D函数用于实例化模型类 格式 [资源://][模块/]模型 </span><span>159</span> <span> * @param string $name 资源地址 </span><span>160</span> <span> * @param string $layer 模型层名称 </span><span>161</span> <span> * @return Model </span><span>162</span> <span>*/</span> <span>163</span> <span>function</span> D(<span>$name</span>='',<span>$layer</span>=''<span>) {} </span><span>164</span> <span>165</span> <span>/*</span><span>* </span><span>166</span> <span> * M函数用于实例化一个没有模型文件的Model </span><span>167</span> <span> * @param string $name Model名称 支持指定基础模型 例如 MongoModel:User </span><span>168</span> <span> * @param string $tablePrefix 表前缀 </span><span>169</span> <span> * @param mixed $connection 数据库连接信息 </span><span>170</span> <span> * @return Model </span><span>171</span> <span>*/</span> <span>172</span> <span>function</span> M(<span>$name</span>='', <span>$tablePrefix</span>='',<span>$connection</span>=''<span>) {} </span><span>173</span> <span>174</span> <span>/*</span><span>* </span><span>175</span> <span> * 解析资源地址并导入类库文件 </span><span>176</span> <span> * 例如 module/controller addon://module/behavior </span><span>177</span> <span> * @param string $name 资源地址 格式:[扩展://][模块/]资源名 </span><span>178</span> <span> * @param string $layer 分层名称 </span><span>179</span> <span> * @return string </span><span>180</span> <span>*/</span> <span>181</span> <span>function</span> parse_res_name(<span>$name</span>,<span>$layer</span>,<span>$level</span>=1<span>) {} </span><span>182</span> <span>183</span> <span>/*</span><span>* </span><span>184</span> <span> * A函数用于实例化控制器 格式:[资源://][模块/]控制器 </span><span>185</span> <span> * @param string $name 资源地址 </span><span>186</span> <span> * @param string $layer 控制层名称 </span><span>187</span> <span> * @param integer $level 控制器层次 </span><span>188</span> <span> * @return Controller|false </span><span>189</span> <span>*/</span> <span>190</span> <span>function</span> A(<span>$name</span>,<span>$layer</span>='',<span>$level</span>=''<span>) {} </span><span>191</span> <span>192</span> <span>/*</span><span>* </span><span>193</span> <span> * 远程调用控制器的操作方法 URL 参数格式 [资源://][模块/]控制器/操作 </span><span>194</span> <span> * @param string $url 调用地址 </span><span>195</span> <span> * @param string|array $vars 调用参数 支持字符串和数组 </span><span>196</span> <span> * @param string $layer 要调用的控制层名称 </span><span>197</span> <span> * @return mixed </span><span>198</span> <span>*/</span> <span>199</span> <span>function</span> R(<span>$url</span>,<span>$vars</span>=<span>array</span>(),<span>$layer</span>=''<span>) {} </span><span>200</span> <span>201</span> <span>/*</span><span>* </span><span>202</span> <span> * 执行某个行为 </span><span>203</span> <span> * @param string $name 行为名称 </span><span>204</span> <span> * @param Mixed $params 传入的参数 </span><span>205</span> <span> * @return void </span><span>206</span> <span>*/</span> <span>207</span> <span>function</span> B(<span>$name</span>, &<span>$params</span>=<span>NULL</span><span>) {} </span><span>208</span> <span>209</span> <span>/*</span><span>* </span><span>210</span> <span> * 去除代码中的空白和注释 </span><span>211</span> <span> * @param string $content 代码内容 </span><span>212</span> <span> * @return string </span><span>213</span> <span>*/</span> <span>214</span> <span>function</span> strip_whitespace(<span>$content</span><span>) {} </span><span>215</span> <span>216</span> <span>/*</span><span>* </span><span>217</span> <span> * 浏览器友好的变量输出 </span><span>218</span> <span> * @param mixed $var 变量 </span><span>219</span> <span> * @param boolean $echo 是否输出 默认为True 如果为false 则返回输出字符串 </span><span>220</span> <span> * @param string $label 标签 默认为空 </span><span>221</span> <span> * @param boolean $strict 是否严谨 默认为true </span><span>222</span> <span> * @return void|string </span><span>223</span> <span>*/</span> <span>224</span> <span>function</span> dump(<span>$var</span>, <span>$echo</span>=<span>true</span>, <span>$label</span>=<span>null</span>, <span>$strict</span>=<span>true</span><span>) {} </span><span>225</span> <span>226</span> <span>/*</span><span>* </span><span>227</span> <span> * URL重定向 </span><span>228</span> <span> * @param string $url 重定向的URL地址 </span><span>229</span> <span> * @param integer $time 重定向的等待时间(秒) </span><span>230</span> <span> * @param string $msg 重定向前的提示信息 </span><span>231</span> <span> * @return void </span><span>232</span> <span>*/</span> <span>233</span> <span>function</span> redirect(<span>$url</span>, <span>$time</span>=0, <span>$msg</span>=''<span>) {} </span><span>234</span> <span>235</span> <span>/*</span><span>* </span><span>236</span> <span> * 缓存管理 </span><span>237</span> <span> * @param mixed $name 缓存名称,如果为数组表示进行缓存设置 </span><span>238</span> <span> * @param mixed $value 缓存值 </span><span>239</span> <span> * @param mixed $options 缓存参数 </span><span>240</span> <span> * @return mixed </span><span>241</span> <span>*/</span> <span>242</span> <span>function</span> S(<span>$name</span>,<span>$value</span>='',<span>$options</span>=<span>null</span><span>) {} </span><span>243</span> <span>244</span> <span>/*</span><span>* </span><span>245</span> <span> * 快速文件数据读取和保存 针对简单类型数据 字符串、数组 </span><span>246</span> <span> * @param string $name 缓存名称 </span><span>247</span> <span> * @param mixed $value 缓存值 </span><span>248</span> <span> * @param string $path 缓存路径 </span><span>249</span> <span> * @return mixed </span><span>250</span> <span>*/</span> <span>251</span> <span>function</span> F(<span>$name</span>, <span>$value</span>='', <span>$path</span>=<span>DATA_PATH) {} </span><span>252</span> <span>253</span> <span>/*</span><span>* </span><span>254</span> <span> * 根据PHP各种类型变量生成唯一标识号 </span><span>255</span> <span> * @param mixed $mix 变量 </span><span>256</span> <span> * @return string </span><span>257</span> <span>*/</span> <span>258</span> <span>function</span> to_guid_string(<span>$mix</span><span>) {} </span><span>259</span> <span>260</span> <span>/*</span><span>* </span><span>261</span> <span> * XML编码 </span><span>262</span> <span> * @param mixed $data 数据 </span><span>263</span> <span> * @param string $root 根节点名 </span><span>264</span> <span> * @param string $item 数字索引的子节点名 </span><span>265</span> <span> * @param string $attr 根节点属性 </span><span>266</span> <span> * @param string $id 数字索引子节点key转换的属性名 </span><span>267</span> <span> * @param string $encoding 数据编码 </span><span>268</span> <span> * @return string </span><span>269</span> <span>*/</span> <span>270</span> <span>function</span> xml_encode(<span>$data</span>, <span>$root</span>='think', <span>$item</span>='item', <span>$attr</span>='', <span>$id</span>='id', <span>$encoding</span>='utf-8'<span>) {} </span><span>271</span> <span>272</span> <span>/*</span><span>* </span><span>273</span> <span> * 数据XML编码 </span><span>274</span> <span> * @param mixed $data 数据 </span><span>275</span> <span> * @param string $item 数字索引时的节点名称 </span><span>276</span> <span> * @param string $id 数字索引key转换为的属性名 </span><span>277</span> <span> * @return string </span><span>278</span> <span>*/</span> <span>279</span> <span>function</span> data_to_xml(<span>$data</span>, <span>$item</span>='item', <span>$id</span>='id'<span>) {} </span><span>280</span> <span>281</span> <span>/*</span><span>* </span><span>282</span> <span> * session管理函数 </span><span>283</span> <span> * @param string|array $name session名称 如果为数组则表示进行session设置 </span><span>284</span> <span> * @param mixed $value session值 </span><span>285</span> <span> * @return mixed </span><span>286</span> <span>*/</span> <span>287</span> <span>function</span> session(<span>$name</span>,<span>$value</span>=''<span>) {} </span><span>288</span> <span>/*</span><span>* </span><span>289</span> <span> * Cookie 设置、获取、删除 </span><span>290</span> <span> * @param string $name cookie名称 </span><span>291</span> <span> * @param mixed $value cookie值 </span><span>292</span> <span> * @param mixed $options cookie参数 </span><span>293</span> <span> * @return mixed </span><span>294</span> <span>*/</span> <span>295</span> <span>function</span> cookie(<span>$name</span>, <span>$value</span>='', <span>$option</span>=<span>null</span><span>) {} </span><span>296</span> <span>297</span> <span>/*</span><span>* </span><span>298</span> <span> * 加载动态扩展文件 </span><span>299</span> <span> * @return void </span><span>300</span> <span>*/</span> <span>301</span> <span>function</span> load_ext_file(<span>$path</span><span>) {} </span><span>302</span> <span>/*</span><span>* </span><span>303</span> <span> * 获取客户端IP地址 </span><span>304</span> <span> * @param integer $type 返回类型 0 返回IP地址 1 返回IPV4地址数字 </span><span>305</span> <span> * @return mixed </span><span>306</span> <span>*/</span> <span>307</span> <span>function</span> get_client_ip(<span>$type</span> = 0<span>) {} </span><span>308</span> <span>309</span> <span>/*</span><span>* </span><span>310</span> <span> * 发送HTTP状态 </span><span>311</span> <span> * @param integer $code 状态码 </span><span>312</span> <span> * @return void </span><span>313</span> <span>*/</span> <span>314</span> <span>function</span> send_http_status(<span>$code</span><span>) {} </span><span>315</span> <span>316</span> <span>//</span><span> 过滤表单中的表达式</span> <span>317</span> <span>function</span> filter_exp(&<span>$value</span><span>) {} </span><span>318</span> <span>319</span> <span>//</span><span> 不区分大小写的in_array实现</span> <span>320</span> <span>function</span> in_array_case(<span>$value</span>,<span>$array</span>) {}