有些时候,开发者需要在进入插件时,默认加载一些自己要用到的函数、类库。此时,可以在插件根目录下声明init.php文件,系统会自动加载!
开发者可以在该文件中加载自己常用的类库,声明一些要用到的函数。
如果开发者需要对插件类添加一些属性和方法,也可在此声明!声明方法为,设置文件的命名空间为插件标识,然后声明init()函数,系统在初始化插件类时,如果检测到该函数,则会自动调用以实现开发者对插件类的一些初始化工作。
示例代码:
以下是微客分销插件初始化文件代码。
<?php/* 插件初始化*/namespace jy_commission;defined(&#39;BY_JYA&#39;) or exit(&#39;error&#39;);function init($plugin){ $plugin->setting=$plugin->plugin_setting(&#39;setting&#39;); $plugin->pay_types=array( &#39;credit&#39;=>&#39;打款到余额&#39;, &#39;wechat&#39;=>&#39;打款到微信零钱&#39;, //&#39;alipay&#39;=>&#39;打款到支付宝&#39;, //&#39;union&#39;=>&#39;打款到银行卡&#39;, ); $plugin->commission_status=array( &#39;0&#39;=>&#39;订单待完成&#39;, &#39;1&#39;=>&#39;待结算&#39;, &#39;2&#39;=>&#39;已结算&#39;, ); $plugin->agent_status=array( &#39;0&#39;=>&#39;正常&#39;, &#39;1&#39;=>&#39;禁用&#39;, ); $plugin->apply_status=array( &#39;0&#39;=>&#39;待审核&#39;, &#39;1&#39;=>&#39;审核通过&#39;, &#39;2&#39;=>&#39;审核不通过&#39;, ); $plugin->balance_status=array( &#39;0&#39;=>&#39;待审核&#39;, &#39;1&#39;=>&#39;审核通过&#39;, &#39;2&#39;=>&#39;审核不通过&#39;, &#39;3&#39;=>&#39;已打款&#39;, ); $plugin->level_types=array( &#39;0&#39;=>&#39;不开启&#39;, &#39;1&#39;=>&#39;一级分销&#39;, &#39;2&#39;=>&#39;二级分销&#39;, &#39;3&#39;=>&#39;三级分销&#39;, &#39;4&#39;=>&#39;四级分销&#39;, &#39;5&#39;=>&#39;五级分销&#39;, &#39;6&#39;=>&#39;六级分销&#39;, &#39;7&#39;=>&#39;七级分销&#39;, &#39;8&#39;=>&#39;八级分销&#39;, &#39;9&#39;=>&#39;九级分销&#39;, ); $plugin->commission_money_types=array( &#39;1&#39;=>&#39;一级佣金&#39;, &#39;2&#39;=>&#39;二级佣金&#39;, &#39;3&#39;=>&#39;三级佣金&#39;, &#39;4&#39;=>&#39;四级佣金&#39;, &#39;5&#39;=>&#39;五级佣金&#39;, &#39;6&#39;=>&#39;六级佣金&#39;, &#39;7&#39;=>&#39;七级佣金&#39;, &#39;8&#39;=>&#39;八级佣金&#39;, &#39;9&#39;=>&#39;九级佣金&#39;, ); $plugin->commission_types=array( &#39;1&#39;=>&#39;不扣除运费&#39;, &#39;2&#39;=>&#39;扣除运费&#39;, ); $plugin->level_up_types=array( &#39;member_num&#39;=>&#39;下线总人数(人)&#39;, &#39;agent_num&#39;=>&#39;下级代理商总人数(人)&#39;, &#39;order_price&#39;=>&#39;分销订单总金额(元)&#39;, &#39;order_num&#39;=>&#39;分销订单总数(个)&#39;, &#39;order_price_next&#39;=>&#39;一级分销订单总金额(元)&#39;, &#39;order_num_next&#39;=>&#39;一级分销订单总数(个)&#39;, &#39;member_num_next&#39;=>&#39;一级下线总人数(人)&#39;, &#39;agent_num_next&#39;=>&#39;一级分销商总人数(人)&#39;, );} |