54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
#
|
|
# @Author: fm453
|
|
# @Date: 2024/7/16
|
|
# @updated: 上午8:48
|
|
# @Email: 1280880631@qq.com
|
|
|
|
namespace backend\controllers;
|
|
|
|
use Yii;
|
|
use yii\data\Pagination;
|
|
use yii\helpers\Url;
|
|
use yii\web\Controller;
|
|
|
|
class Common extends Controller
|
|
{
|
|
protected $pid = 0;
|
|
public $postdata = [];
|
|
//替代常规的_construct 析构函数;其他方法调用前执行
|
|
public function init()
|
|
{
|
|
parent::init();
|
|
$get = Yii::$app->request->get();
|
|
$session = Yii::$app->session;
|
|
$this->pid = $session->get('pid');
|
|
if (isset($_GET['pid']) && (int)$_GET['pid'] > 0) {
|
|
$session->set('pid', (int)$_GET['pid']);
|
|
$this->pid = (int)$_GET['pid'];
|
|
}
|
|
|
|
if (!$this->pid) {
|
|
return Yii::$app->response->redirect(['index/index']);
|
|
}
|
|
//判断请求内容类型 content-type,支持 json请求
|
|
$postdata = Yii::$app->request->post();
|
|
$headers = Yii::$app->request->headers;
|
|
$contentType = $headers->get('content-type');
|
|
if ($contentType=="application/json") {
|
|
$postdata = json_decode(file_get_contents('php://input'), true);
|
|
}
|
|
$this->postdata = $postdata;
|
|
}
|
|
|
|
public function result($msg, $data=null, $code=0)
|
|
{
|
|
$return = [];
|
|
$return['code'] = $code;
|
|
$return['msg'] = $msg;
|
|
if ($data) {
|
|
$return['data'] = $data;
|
|
}
|
|
exit(json_encode($return, JSON_UNESCAPED_UNICODE));
|
|
}
|
|
} |