


data-id="1190000004902725">
Preface
Good habits create a good life, and you must be good at summarizing during development. Today I will continue to share some useful information with you. Fans who follow me will benefit from it. Below are some notes I compiled when calling the interface on the PC, as well as reminders of things you need to pay attention to!
Cause Analysis
1. First, let me talk about why the interface is called on the PC side to obtain data!
I’ll give you a link: http://www.bitscn.com/pdb/php/201411/402…. After reading this article, you will probably understand what I mean.
2. Integrating relevant information is not only conducive to the acquisition of information, but also serves as a lesson for others. People who have planted trees can benefit future generations, right? Haha, I am a philanthropist.
Note organization
1. Three ways for Yii2 PC to call the interface to obtain data
PHP method to call the Api interface
<code> 1、直接在方法里引用接口的url。 2、通过file_get_contents()函数获取url的数据。 3、把获取到的JSON格式数据进行反转。(可选) 4、参考网址:http://www.jb51.net/article/20705.htm //PHP远程调用URL 例: $url='http://api.xxx.com/v1/departments?id=list&company_id=1'; $data=file_get_contents($url); $data_1 = json_decode($data,true); //JSON反转</code>
Ajax method to call the Api interface
<code> 例: $.ajax({ type:"POST", url: //你的请求程序页面随便啦(接口地址) async:false,//同步:意思是当有返回值以后才会进行后面的js程序。 data://请求需要发送的处理数据 success:function(msg){ if (msg) {//根据返回值进行跳转 window.location.href = '你的跳转的目标地址(页面地址)'; } }</code>
JQ method to call the Api interface
<code>例: <script type="text/javascript" src="/apihandonesvn/frontend/web/assets/68738eee/jquery-1.11.2.min.js"></script> <script type="text/javascript"> //1、GET方式 $.get('http://api.XXX.com/v1/departments?grade=1',function(data){ // console.log(data);//输出内容,类似alert() $('#content').html(data); }); //2、POST方式 $.post('http://api.XXX.com/v1/departments?grade=1',{a:1,b:2,c:3},function(data){ $('#content').html(JSON.stringify(data)); }); </script></code>
Added: If you use the latter two methods, add the following code at the top of all methods of the controller corresponding to the interface
<code> public function behaviors() { return ArrayHelper::merge([ [ 'class' => Cors::className(), 'cors' => [ 'Origin' => ['http://www.ceshi.com'],//PC端的Url 'Access-Control-Request-Method' => ['GET','POST','PUT','DELETE', 'HEAD', 'OPTIONS'], ], 'actions' => [ 'index' => [ 'Access-Control-Allow-Credentials' => true, ] ] ], ], parent::behaviors()); }</code>
The above three methods of calling the interface on the PC side have been tested by me and are all feasible. You can choose what you like.
2. When calling the interface on the PC, how does the interface obtain the uid?
At this time, the interface cannot be obtained using Yii:$app->user->id that comes with Yii, because it is impossible to log in through the interface. To obtain the uid of the current logged-in user through the interface, you can pass an access-token through the PC, and then use get on the interface to find out the uid and solve the problem.
This method can also be imitated when the interface obtains other parameters.
3. Report: PHP Warning – yiibaseErrorException
Invalid argument supplied for foreach() error problem and solution
This error is caused by looping empty data. As long as a judgment must be added before the data is looped to ensure that the data exists before the loop can be looped. solved. Although this is not a particularly difficult error to solve, we still have to pay attention to details, as details determine success or failure.
Reminder
1. The PC calls the interface for local testing. It is best not to match the local interface address with the Internet, because then it will go to the local interface first. If the local interface is good, it is difficult to find the reason.
Related information
PHP (CURL) POST data calling API simple example: http://eyexiaobo.iteye.com/blog/1100712
The above introduces the notes and precautions for calling the interface on the PC side, including precautions and interface content. I hope it will be helpful to friends who are interested in PHP tutorials.

C++开发中,空指针异常是一种常见的错误,经常出现在指针没有被初始化或被释放后继续使用等情况下。空指针异常不仅会导致程序崩溃,还可能造成安全漏洞,因此需要特别注意。本文将介绍如何避免C++代码中的空指针异常。初始化指针变量C++中的指针必须在使用前进行初始化。如果没有初始化,指针将指向一个随机的内存地址,这可能导致空指针异常。要初始化指针,可以将其指向一个可

Python作为一种高级编程语言,具有易学易用和开发效率高等优点,在开发人员中越来越受欢迎。但是,由于其垃圾回收机制的实现方式,Python在处理大量内存时,容易出现内存泄漏问题。本文将从常见内存泄漏问题、引起问题的原因以及避免内存泄漏的方法三个方面来介绍Python开发过程中需要注意的事项。一、常见内存泄漏问题内存泄漏是指程序在运行中分配的内存空间无法释放

Golang是一种强类型、静态编程语言,其函数设计灵活,其中可变函数参数也是常见的实现方式之一,通常会用于函数参数个数不确定或者需要动态参数传递的场景。可变函数参数的使用虽然方便有效,但是也存在一些需要注意的问题,本文将详细介绍一下可变函数参数的使用注意事项。一、什么是可变函数参数?在Golang中,如果我们需要定义一个函数,但是无法确定该函数的参数个数,那

利用localStorage存储数据的步骤和注意事项本文主要介绍如何使用localStorage来存储数据,并提供相关的代码示例。LocalStorage是一种在浏览器中存储数据的方式,它可以将数据保存在用户的本地计算机上,而不需要通过服务器。下面是使用localStorage存储数据的步骤和需要注意的事项。步骤一:检测浏览器是否支持LocalStorage

Laravel是一种广泛用于开发Web应用程序的PHP框架。它提供了许多方便易用的功能,以帮助开发者快速构建和维护应用程序。然而,与所有Web开发框架一样,Laravel也有一些可能导致安全漏洞的地方。在本文中,我们将重点介绍一些常见的安全漏洞,并提供一些注意事项,以帮助开发者避免这些问题。输入验证输入验证是防止用户提交恶意数据到应用程序的重要步骤。在Lar

提到爱奇艺视频,大家都应该很熟悉。作为国内最受欢迎的视频播放软件之一,它是许多朋友观看剧集的必备工具。如果你在使用爱奇艺视频观看电影或电视剧时,看到一些有趣的片段,想要进行剪辑,该怎么办呢?接下来,我将为大家介绍一下在爱奇艺视频上如何剪辑视频,希望能对需要的朋友有所帮助在爱奇艺上如何进行视频剪辑?打开手机上的爱奇艺视频应用,并登录自己的账号。在登录后,找到要剪辑的视频并点击播放。进入视频播放界面后,点击屏幕,在左侧会出现选项图标。选择中间的视频截取图标,就会进入视频截取界面在视频截取界面,你可以

VueRouter重定向功能实现中的注意事项在使用Vue.js开发Web应用时,VueRouter是必不可少的一个插件,它提供了路由功能、导航守卫等,使得页面之间的跳转和管理变得更加简单和便捷。其中一个重要的功能就是重定向,可以实现在用户访问某个url时自动跳转到另一个url。本文将介绍在实践中实现VueRouter重定向功能时需要注意的事项,并给出

很多网友询问小编哪里可以下载到最安全的windows7iso镜像文件?网上搜索关于windows7iso镜像文件的资讯内容比较少,所以很多用户都不知道如何下载。今天小编给大家带来了win732以及win764位系统镜像文件的下载地址,大家快来看看吧。Windows7iso镜像系统硬件要求处理器:64位处理器;内存:最低1GB,是64位操作系统显卡:支持DirectX9128M显存:128MB硬盘空间:16G以上Windows7简体中文旗舰版x86ISO下载文件名:cn_windows_7_ult


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
