PHP Laravel adding custom classes and functions
That's what I'm doing now. I only have the student's number, now I want to use the list to display these numbers, names, gender, professional information.
Of course, the information is there, in our base library. I'm going to query the data using the underlying library API we wrote ourselves.
I need to implement a Curlhelper class in my framework and then instantiate it with a method, because only some of the pages need these features.
So how is this going to be implemented in my framework?
First I set up a folder under the app directory, called Tools, to build two files inside,
A class called curlhelper.php mainly has a curlhelper.
The other is functions.php. This is where some of the functions used by the program are stored.
Class I will not write, I am here to illustrate such a situation:
The function still needs to be written, because in the end we need to call it in the controller or model.
function Getcurl () {
static $API = null;
if (! $api) {
$api = new Curlhelper (//parameter);
}
return $API;
}
That's the whole thing. Below we need to introduce the Curlhelper class into the framework.
Using composer Dumpautoload This class can be found through dependency injection.
As for the commonly used functions, they are put into memory when the program is loaded.
So we can even get through require app_path () in public/index.php. ' /tools/functions.php '; to load.
This allows us to invoke our Getcurl () function directly in the controller to instantiate the class.
Knowledge can change your fate and 中文版 can accomplish your future.
Best Wishes.