后台配置参数写在文件上

1.控制器页indexController.php

public function sms_set( $templ = '' ){
        $sms = include(  APP_PATH  . 'Home/Conf/sms.php' );
        
        if( IS_POST ){
            foreach( $sms as $k=>$v ){
                if( isset( $_POST[$k] ) ){
                    $sms[$k] = $_POST[$k];
                }
            }

            $file_length = file_put_contents(  APP_PATH  . 'Home/Conf/sms.php', '<?php return ' . iconv('utf-8','gbk',var_export($sms,true)) . '; ?>' );
            
            if( $file_length ){
                $this->success('保存成功!');
            } else {
                $this->error('保存失败!请检查文件权限');
            }
            return;
        }
        foreach($sms as $k=>$v ){
            $v=iconv('gbk','utf-8',$v);
            $this->assign( $k, $v );
        }
        $this->display( $templ );
    }

2.设置页面sms_set.php

<?php return array (
  'name' => '18681033111',
  'pwd' => '43EC43C36ECFED004BF4C5384111',
  'content' => NULL,
  'mobile' => NULL,
  'stime' => '',
  'sign' => '社区',
  'type' => 'pt',
  'extno' => '',
); ?>

 3.html页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>
            无标题文档
        </title>
        <link href="/sncss/css/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <div class="place">
            <span>
                位置:
            </span>
            <ul class="placeul">
                <li>
                    <a href="#">
                        首页
                    </a>
                </li>
                <li>
                    <a href="#">
                        表单
                    </a>
                </li>
            </ul>
        </div>
        <div class="formbody">
            <div class="formtitle">
                <span>
                    短信接口设置
                </span>
            </div>
            <form id="form1" name="form1" method="post" action="/admin.php/Home/Index/sms_set">
                <input name="UE_account" type="hidden" class="dfinput" value="{$userdata['ue_account']}"
                />
                <ul class="forminfo">
                    <i>
                    </i>
                    </li>
<!-- added by skyrim -->
<!-- purpose: seperate masses and managers -->
<!-- version: 5.0 -->
                    
                    
<!-- added ends -->
                    
                    
                    <li>
                        <label>
                            用户账号
                        </label>
                        <input name="name" type="text" id="name"
                        class="dfinput" required="true" value="{$name}" />
                        <i>必填参数。
                        </i>
                    </li>
                    <li>
                        <label>
                            接口密码
                        </label>
                        <input name="pwd" type="text" id="pwd"
                        class="dfinput" required="true" value="{$pwd}" />
                        <i>必填参数。(web平台:基本资料中的接口密码)
                        </i>
                    </li>
                    
                    <li>
                        <label>
                            发送时间
                        </label>
                        <input type="text" value="{$stime}" id="stime"
                        class="dfinput" name="stime" >
                        <i>可选参数。指定时间发送,如:2012-08-01 8:20:23。不填时为当前时间发送
                        </i>
                    </li>
                    <li>
                        <label>
                            用户签名
                        </label>
                        <input type="text" value="{$sign}" id="sign"
                        class="dfinput" name="sign" required="">
                        <i>必填参数。
                        </i>
                    </li>
                    <li>
                        <label>
                            类型
                        </label>
                        <input type="text" value="pt" id="type"
                        class="dfinput" name="type" required="" >
                        <i>必填参数。固定值pt
                        </i>
                    </li>
                    <li>
                        <label>
                            扩展码
                        </label>
                        <input type="text" value="{$extno}" id="extno"
                        class="dfinput" name="extno" >
                        <i>可选参数,扩展码,用户定义扩展码,只能为数字
                        </i>
                    </li>

                    <li>
                        <label>
                            &nbsp;
                        </label>
                        <input name="" type="submit" class="btn" value="确认保存" />
                    </li>
                </ul>
            </form>
            <style>
                .pages a,.pages span { display:inline-block; padding:2px 5px; margin:0
                1px; border:1px solid #f0f0f0; -webkit-border-radius:3px; -moz-border-radius:3px;
                border-radius:3px; } .pages a,.pages li { display:inline-block; list-style:
                none; text-decoration:none; color:#58A0D3; } .pages a.first,.pages a.prev,.pages
                a.next,.pages a.end{ margin:0; } .pages a:hover{ border-color:#50A8E6;
                } .pages span.current{ background:#50A8E6; color:#FFF; font-weight:700;
                border-color:#50A8E6; }
            </style>
            <div class="pages">
                <br />
                <div align="right">
                    {$page}
                </div>
            </div>
        </div>
    </body>

</html>
原文地址:https://www.cnblogs.com/lvchenfeng/p/5392015.html