电话
13363039260
开发实例:模块内容用户投稿后,通知到指定的账号(可多个账号)
后台设置效果界面:
例子以Demo模块为例,其他模块请自己修改目录名称。
1、新建配置控制器文件:dayrui/App/Demo/Controllers/Admin/Param.php
<?php namespace Phpcmf\Controllers\Admin;
// 此文件继承于dayrui/Fcms/Control/Admin/Config.php
class Param extends \Phpcmf\Admin\Config
{
public function index() {
$this->_Module_Param();
}
}
2、新建控制器模板文件:dayrui/App/Demo/Views/param.html
{template "header.html"}
<div class="note note-danger">
<p><a href="javascript:dr_update_cache();">{dr_lang('更改数据之后需要更新缓存之后才能生效')}</a></p>
</div>
<form action="" class="form-horizontal" method="post" name="myform" id="myform">
{$form}
<div class="portlet bordered light myfbody">
<div class="portlet-title tabbable-line">
<ul class="nav nav-tabs" style="float:left;">
<li class="{if $page==0}active{/if}">
<a href="#tab_0" data-toggle="tab" onclick=$('#dr_page').val('0')"> <i class="fa fa-cog"></i> {dr_lang('参数设置')} </a>
</li>
</ul>
</div>
<div class="portlet-body">
<div class="form-body">
<div class="form-group" id="dr_row_username">
<label class="control-label col-md-1">{dr_lang('内容用户投稿后通知')}</label>
<div class="col-md-11">
<input class="form-control " type="text" name="data[notice][post][username]" value="{htmlspecialchars((string)$data['notice']['post']['username'])}" style="width:80%;" data-role="tagsinput" />
<div class="mt-checkbox-inline">
<label class="mt-checkbox mt-checkbox-outline">
<input type="checkbox" name="data[notice][post][mobile]" value="1" {if $data['notice']['post']['mobile']}checked{/if} /> {dr_lang('短信')} <span></span>
</label>
<label class="mt-checkbox mt-checkbox-outline">
<input type="checkbox" name="data[notice][post][email]" value="1" {if $data['notice']['post']['email']}checked{/if} /> {dr_lang('邮件')} <span></span>
</label>
<label class="mt-checkbox mt-checkbox-outline">
<input type="checkbox" name="data[notice][post][weixin]" value="1" {if $data['notice']['post']['weixin']}checked{/if} /> {dr_lang('微信')} <span></span>
</label>
<label class="mt-checkbox mt-checkbox-outline">
<input type="checkbox" name="data[notice][post][notice]" value="1" {if $data['notice']['post']['notice']}checked{/if} /> {dr_lang('消息')} <span></span>
</label>
<label class="mt-checkbox mt-checkbox-outline">
<a href="javascript:dr_iframe_show('{dr_lang('通知内容')}', '{dr_url('member/setting_notice/edit')}&file=my_send_{APP_DIR}_post', '90%','90%', 'nogo');">{dr_lang('内容设置')}</a>
</label>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="portlet-body form myfooter">
<div class="form-actions text-center">
<button type="button" onclick="dr_ajax_submit('{dr_now_url()}&page='+$('#dr_page').val(), 'myform', '2000')" class="btn green"> <i class="fa fa-save"></i> {dr_lang('保存')}</button>
</div>
</div>
</form>
{template "footer.html"}
3、访问这个页面,并设置数据,效果见首图
admin.php?s=demo&c=param&m=index
4、模块钩子开发,写入程序逻辑代码:dayrui/App/Demo/Config/Hooks.php
<?php
/**
* 应用自己的钩子
*
*/
\Phpcmf\Hooks::on('module_content_after', function($data, $old) {
if (MOD_DIR == 'demo') {
// 内容发布或者修改之后
my_send_users_tpl("post", $data);
}
});
function my_send_users_tpl($name, $data) {
if (isset(\Phpcmf\Service::C()->module['setting']['param']['notice'][$name]['username']) && \Phpcmf\Service::C()->module['setting']['param']['notice'][$name]['username']) {
$var = dr_array2array($data[1], $data[0]);
$fields = \Phpcmf\Service::C()->module['field'];
$fields['inputtime'] = ['fieldtype' => 'Date'];
$fields['updatetime'] = ['fieldtype' => 'Date'];
$var = \Phpcmf\Service::L('Field')->format_value($fields, $var, 1);
$arr = explode(',', \Phpcmf\Service::C()->module['setting']['param']['notice'][$name]['username']);
foreach ($arr as $autor) {
$user = dr_member_username_info($autor);
if (!$user) {
log_message('error', '自定义钩子:已开启通知提醒,但通知人['.$autor.']有误');
} else {
\Phpcmf\Service::L('Notice')->send_notice_user(
'my_send_'.APP_DIR.'_'.$name,
$user['id'],
$var,
\Phpcmf\Service::C()->module['setting']['param']['notice'][$name],
1 // 1立即发送
);
}
}
}
}