laravel怎么創(chuàng)建函數(shù)

laravel創(chuàng)建函數(shù)的方法:1、在app目錄創(chuàng)建Common文件夾;2、創(chuàng)建文件自定義的函數(shù)文件;3、書(shū)寫(xiě)自定義的函數(shù)方法;4、注冊(cè)自定義的函數(shù)文件;5、調(diào)用自定義的函數(shù)即可。

laravel怎么創(chuàng)建函數(shù)

本文操作環(huán)境:windows7系統(tǒng)、Laravel5.2版,DELL G3電腦。

laravel怎么創(chuàng)建函數(shù)?

laravel創(chuàng)建自定義函數(shù):

目前使用的laravel版本是5.2.*

1,在app目錄創(chuàng)建Common文件夾

2,在剛剛創(chuàng)建的文件夾Common中創(chuàng)建文件自定義的函數(shù)文件如helpers,php

3,在自定義的函數(shù)文件中書(shū)寫(xiě)自定義的函數(shù)方法,如:

if?(?!function_exists(?'p'?)?) { function?p(?$data?)?{ echo?"<pre class="brush:php;toolbar:false">"; print_r($data); echo "

“; } }

4,在根目錄中的bootstrap目錄下的autoload.php文件中注冊(cè)剛剛自定義的函數(shù)文件

if(file_exists(DIR?.?'/../app/Common/helpers.php')) { require?DIR?.?'/../app/Common/helpers.php'; }

5,現(xiàn)在就可以在項(xiàng)目中的任何位置調(diào)用你自定義的函數(shù)啦

推薦學(xué)習(xí)教程:《laravel》《laravel

以上就是

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊5 分享