前面我们说过在abstract控制器类中初始了应用的配置,系统对此提供了快捷的操作方法。
要使用系统的应用配置,需要在后台控制器中创建setting控制器类,和后台视图setting.php。
创建setting控制器以后,也可直接在 后台-扩展管理中,点击设置按钮进入配置(缺少setting控制器的情况下该按钮为灰色)。
配置好以后就可以使用 $this->setting['var']在控制器中调用,在后台视图中用{$SETTING['var']}来调用。
§ setting控制器
文件:./apps/book/controller/admin/settting.php
class controller_admin_setting extends book_controller_abstract
{
function __construct(& $app)
{
parent::__construct($app);
if (!license('system')) $this->showmessage('请联系 <a href="http://www.cmstop.com/" target="_blank">CmsTop</a> 官方购买授权');
}
public function index()
{
if ($this->is_post())
{
$setting = new setting();
$result = $setting->set_array($this->app->app, $_POST['setting']) ? array('state'=>true,'message'=>'保存成功') : array('state'=>false,'error'=>'保存失败');
echo $this->json->encode($result);
}
else
{
$head = array('title'=>$this->setting['bookname'] .'设置');
$this->view->assign('head', $head);
$this->view->assign('setting', $this->setting);
$this->view->display('setting');
}
}
}
§ setting视图
文件:./apps/book/view/setting.php
<?php $this->display('header', 'system');?>
<div class="bk_10"></div>
<form id="book_setting" name="book_setting" action="?app=book&controller=setting&action=index" method="POST">
<table width="98%" border="0" cellspacing="0" cellpadding="0" class="table_form mar_l_8">
<caption>留言本基本设置</caption>
<tr>
<th width="120">留言本标题:</th>
<td colspan="2"><input type="text" name="setting[bookname]" value="<?=$setting['bookname']?>" size="30"/></td>
</tr>
<tr>
<th>验证码是否开启:</th>
<td colspan="2">
<input type="radio" id="l7" name="setting[iscode]" value="1" class="radio" <?php if ($setting['iscode']) echo 'checked';?>/> <label for="l7">是</label>
<input type="radio" id="l8" name="setting[iscode]" value="0" class="radio" <?php if (!$setting['iscode']) echo 'checked';?>> <label for="l8">否</label>
</td>
</tr>
<tr>
<th>是否开启审核:</th>
<td colspan="2">
<input type="radio" id="l7" name="setting[ischeck]" value="1" class="radio" <?php if ($setting['ischeck']) echo 'checked';?>/> <label for="l7">是</label>
<input type="radio" id="l8" name="setting[ischeck]" value="0" class="radio" <?php if (!$setting['ischeck']) echo 'checked';?>> <label for="l8">否</label>
</td>
</tr>
<tr>
<th>Email通知:</th>
<td colspan="2"><input id="email1" type="checkbox" name="setting[emailnotice]" value="1" class="radio" <?php if ($setting['emailnotice']) echo 'checked';?>/>
<label class="aler" for="email1"> 当留言有回复时通知留言人</label> </td>
</tr>
<tr>
<th>邮件标题:</th>
<td colspan="2"><input id="email2" type="text" name="setting[emailtitle]" value="<?php echo $setting['emailtitle'] ? $setting['emailtitle'] : '您在'.$setting['bookname'].'的留言已经有回复';?>" size="32"/></td>
</tr>
<tr>
<th class="vtop">邮件内容:</th>
<td colspan="2"><textarea id="email3" name="setting[emailcontent]" rows="8" cols="32"><?php echo $setting['emailcontent'] ? $setting['emailcontent']:'HI,'.$_username.' 您好 您在我们网站上的留言已有回复。你的留言内容:$content '.$setting['showmanage'].' 回复:';?></textarea> </td>
</tr>
<tr>
<th></th>
<td colspan="2" valign="middle"><br/>
<input type="submit" id="submit" value="保存" class="button_style_2"/>
</td>
</tr>
</table>
</form>
<script type="text/javascript">
$(function(){
$('#book_setting').ajaxForm('submit_ok');
});
function submit_ok(json) {
if(json.state) ct.ok(json.message);
else ct.error(json.error);
}
</script>
<?php $this->display('footer', 'system');?>