PHP Laravel adds custom classes and functions

Source: Internet
Author: User
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.


  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.