


Notes and precautions for calling the interface on PC, precautions in late pregnancy, precautions when flying, precautions after miscarriage
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.

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

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),

Zend Studio 13.0.1
Powerful PHP integrated development environment

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.