Methods for extending functions and extending custom classes in the Laravel framework.

Source: Internet
Author: User

Methods for extending functions and extending custom classes in the Laravel framework.

1. Expand your class

Create the libraries \ class directory under app /.

Then myTest. php class name format camper myTest

Copy codeThe Code is as follows:
<? Php
Class myTest
{
Public function test ()
{
Return '1asdasd111 ';
}
}

In app/start/global. php

Copy codeThe Code is as follows:
ClassLoader: addDirectories (array (
App_path (). '/commands ',
App_path (). '/controllers ',
App_path (). '/models ',
App_path (). '/database/seeds ',
App_path (). '/libraries/class', // Add this section
));
Load with make
Copy codeThe Code is as follows:
<? Php
Class HomeController extends BaseController {
Protected $ layout = 'layouts. main ';
Public function index ()
{
$ A = App: make ('mytest'); // usage
Echo $ a-> test ();
}
}

2. Expand your own functions

Create the libraries \ function directory in app /.

Create helper. php

Function Format. Use function_exists as follows to prevent duplicate names with the system.
Copy codeThe Code is as follows:
If (! Function_exists ('test2 '))
{
Function test2 ()
{
Echo 2222222222222222;
}
}

Method 1:

In app/filters. php
Copy codeThe Code is as follows:
App: before (function ($ request)
{
Require app_path (). '/libraries/function/helper. php'; // load custom functions
});

Method 2:

In app/bootstrap/autoglad. php

Copy codeThe Code is as follows:
Require _ DIR _. '/../app/functions. php'; // introduce the custom function library

I think the method will be better.


How to reference the class functions or methods of custom dll

Default. aspx code:
<% @ Page Language = "C #" %>
<% @ Import Namespace = "shangqi" %>
<%
Sq s = new sq ();
.........
.........
%>

If you reference DLL in the default. aspx. cs file:
Add the shangqi. dll reference under the project reference, and then add the using shangqi in the Code;

In this way, OK ,,,

How does Python call functions in a custom class?

Hello:
Set the first parameter in the custom function:
Self
This is agreed by python;
You don't need to worry about it when calling it. It is equivalent to this!

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.