Home > PHP Framework > YII > body text

How to use tool functions in yii framework

PHPz
Release: 2020-02-27 14:04:41
Original
2059 people have browsed it

How to use tool functions in yii framework

First we create a file in the project root directory, such as:

/utils/function.php

The content of the file is as follows:

(Related tutorials recommended: yii framework)

<?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; }
Copy after login

The second step is to add the following sentence in web/index.php

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

Below we can Use these methods globally.

For more programming related content, please pay attention to the Programming Introduction column on the php Chinese website!

The above is the detailed content of How to use tool functions in yii framework. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template