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

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

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

一、公共事件  appscommoncommon.php

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

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

二、公共配置 appscommonconfig.php

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

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

三、公共语言包 appscommonlangzh-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')}

四、公共控制器  appscommoncommon.php

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

五、公共模块 appscommoncommon.php

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

原文地址:https://www.cnblogs.com/wesky/p/6815320.html