Laravel implements Facades. laravelfacades_PHP tutorial

Source: Internet
Author: User
Laravel implements the Facades function, laravelfacades. Laravel implements the Facades function. anyone who has used Laravel in laravelfacades knows the power of Facades. let's create a Facades instance together. If any, Laravel implements the Facades function and laravelfacades

Anyone who has used Laravel knows the power of Facades. let's create a Facades instance together. If there are any errors, please do not give me any further advice.

1. implement automatic Laravel loading

Create the app/lib/Myapp directory and add the directory to composer. json.

1 "autoload": {        2     "psr-0":{3         "Myapp":"app/lib"4     }5 }    

  

  2. implement function classes

Implementation class app/lib/Myapp/Test. php

1
 

  

3. implement ServiceProvider

Implement app/lib/Myapp/TestServiceProvider. php. this class mainly adds the function class to the Ioc container:

  app['test'] = $this->app->share(            function ($app) {                return new \Myapp\Test();        });    }}

4. implement a Facade instance

Implements app/lib/Myapp/Facades/TestFacades. php. this class is mainly beautifying and the calling form of member functions is similar to that of static methods.

1
  

  

5. load ServiceProvider

Add the following configuration to providers in app/config/app. php:

1 'providers' => array(   2   'Myapp\TestServiceProvider'3 ),

Add an alias to aliases in app/config/app. php:

1 'aliases' => array(2     'TestClass'            =>  'Myapp\Facades\TestFacades',3 ),

Next, you can use this function class in the form of TestClass: do () in the project.

Http://www.bkjia.com/PHPjc/944439.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/944439.htmlTechArticleLaravel to achieve the Facades function, laravelfacades using Laravel students know the power of Facades, let us create a Facades instance. If something is incorrect, return...

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.