Laravel extension functions, extending custom classes in the framework, Laravel framework
First, expand their own classes
Create a directory under app/libraries\class
Then mytest.php class name format hump myTest
Copy the Code code as follows:
<?php
Class MyTest
{
Public Function test ()
{
Return ' 1asdasd111 ';
}
}
In app/start/global.php
Copy the Code code as follows:
Classloader::adddirectories (Array (
App_path (). ' /commands ',
App_path (). ' /controllers ',
App_path (). ' /models ',
App_path (). ' /database/seeds ',
App_path (). ' /libraries/class ',//Add this paragraph
));
Loading with Make
Copy the Code code as follows:
<?php
Class HomeController extends Basecontroller {
protected $layout = ' layouts.main ';
Public Function Index ()
{
$a = App::make (' mytest '); Usage
echo $a->test ();
}
}
Second, expand their own functions
Create a directory under app/libraries\function
Establish helper.php
function formats, such as function_exists, to prevent duplication with the system
Copy the Code code as follows:
if (! function_exists (' test2 '))
{
function Test2 ()
{
Echo 2222222222222222;
}
}
Method One:
In app/filters.php
Copy the Code code as follows:
App::before (function ($request)
{
Require App_path (). ' /libraries/function/helper.php '; Loading a custom function
});
Method Two:
In app/bootstrap/autolad.php
Copy the Code code as follows:
Require __dir__. ' /.. /app/functions.php '; Introduction of Custom Function libraries
I feel that the method will be better.
How to refer to a class function or method of a custom DLL
Default.aspx's code:
<%@ page language= "C #"%>
<%@ Import namespace= "Shangqi"%>
<%
Sq s = new sq ();
.........
.........
%>
If the DLL is referenced under the Default.aspx.cs file:
Add the Shangqi.dll reference under the project reference, and then include the using Shangqi in the code;
That's OK 、、、
How does python invoke a function in a custom class?
How are you doing:
The first parameter you want to set in your custom function is:
Self
This is the Python convention;
The call can be used without it, which is equivalent to this!
http://www.bkjia.com/PHPjc/874637.html www.bkjia.com true http://www.bkjia.com/PHPjc/874637.html techarticle laravel extension Functions in the framework, extending the custom class method, Laravel framework one, extending its own class under app/to establish the directory Libraries\class then mytest.php the class name format hump MyT ...