Thinkphp5笔记六:公共模块common的使用

common模块属于公共模块,Thinkphp框架,默认就能调用。

实际用处:任何模块都可能用到的模型、控制、事件提取出来放到公共模块下。

 

一、公共事件  apps\common\common.php

作用:一般存放密码加密、下拉框封装、读取某文件夹下文件

/**
 * 密码加密
 * @param string $password
 * @param string $password_salt
 * @return string
 */
function password($password, $password_salt){
    return md5(md5($password) . md5($password_salt));
}

二、公共配置 apps\common\config.php

把Index模块、Admin模块公用的部分提取出来放到这里面,如:公用的模板路径

'template'               => [
    // 模板路径
    'view_path'    => 'template/',
]

 

三、公共语言包 apps\common\lang\zh-cn.php

比如经常用到的词 提交成功、提交失败、执行成功、执行错误、添加成功、添加失败、修改成功、修改失败、删除成功、删除失败... 可以放到公共语言包,在Index模块、Admin模块都可以用的到

 

<?php
/**
 * 全局语言包
 * zh-cn
 * */
return [
    'success'          => '执行成功',
    'error'            => '执行失败',

    'add_success'      => '添加成功',
    'add_error'        => '添加失败',

    'edit_success'     => '修改成功',
    'edit_error'       => '修改失败',

    'delete_success'   => '删除成功',
    'delete_error'     => '删除失败',

];

php页面调用: $lang = lang('success')

html页面调用:{:lang('success')}

 

四、公共控制器  apps\common\common.php

跟上面差不多个意思 Index模块、Admin模块都能用到的放这里

 

五、公共模块 apps\common\common.php

跟上面差不多个意思 Index模块、Admin模块都能用到的放这里

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值