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!