Rumah  >  Artikel  >  rangka kerja php  >  yii框架中工具函数怎么使用

yii框架中工具函数怎么使用

PHPz
PHPzasal
2020-02-27 14:04:412009semak imbas

yii框架中工具函数怎么使用

首先我们在项目根目录下创建文件,如:

/utils/function.php

文件内容如下:

(相关教程推荐:yii框架

<?php
 
function dd($obj)
{
    echo "<pre class="brush:php;toolbar:false">";
    var_dump($obj);
    echo "
"; } function get($url) { //初始化 $ch = curl_init(); //设置选项,包括URL curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查 // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); // 从证书中检查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); //执行并获取HTML文档内容 $output = curl_exec($ch); if($error=curl_error($ch)){ return $error; } //释放curl句柄 curl_close($ch); return $output; } function post($url, $data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // post数据 curl_setopt($ch, CURLOPT_POST, 1); // post的变量 curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $output = curl_exec($ch); curl_close($ch); return $output; }

第二步,在web/index.php里面添加下面一句话

require (__DIR__.&#39;/../utils/function.php&#39;);

下面我们就可以在全局使用这些方法了。

更多编程相关内容,请关注php中文网编程入门栏目!

Atas ialah kandungan terperinci yii框架中工具函数怎么使用. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn