Laravel extension functions, extending custom classes in the framework, Laravel Framework _php Tutorial

Source: Internet
Author: User

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 ...

  • 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.