首页 > php面向对象 > php 模版设计模

php 模版设计模

这个模版,不是smarty的那种模版引擎,不是template。,是一种面向对象设计模式方法,使用的地方譬如,作品easerver中,ui部分用的是wxpython,我现在想换成qt,感觉模版在这种功能就能起到一些作用.

重点是,核心功能封装于主类,让子类去继承应用,程序以php代码做演示,代码如下:

<?php
/*
 *系统服务类
*/
class server {
    //获取的服务项目列表
    protected $sl = array(
        'apache' => 'httpd.exe',
        'nginx' => 'nginx.exe',
        'memcache' => 'memcached.exe'
    );
    protected $select = '服务key';
    //获取服务列表
    public function getlist() {
        return $this->sl;
    }
    //启动服务操作
    public function start() {
        start $this->select;
    }
    //停止服务操作
    public function stop() {
        stop $this->select;
    }
    //重起服务
    public function reboot() {
        reboot $this->select;
    }
    //选择要操作的服务
    public function setselect($name) {
        $this->select = $this->sl[$name];
    }
}
//显示界面
class wxpython extends server {
    public function __construct() {
        parent::__construct();
    }
    //窗体
    public function window() {
        //生成一个表格,提供给用户选择服务
        $this->table($this->getlist());
        //生成一个启动按钮,他的点击时间为启动服务
        $this->startbut->bind('onclick', $this->start()); //启动
        $this->stopbut->bind('onclick', $this->stop()); //关闭
        $this->rebootbut->bind('onclick', $this->reboot()); //重起
        
    }
    //行选择的时候
    public function rowsonselect() {
        $this->setselect($this->tableselect());
    }
}
?>

这样看来,如果我想换qt的操作界面,只需要把wxpython 换成pyqt的界面生成,一样是几个按钮,给他们指定事件就可以了.

或许指定的语法不一样,比如wxpython用 bind指定事件,qt库就不是,更换ui库不需要修改内核功能部分.


教程链接:http://www.phprm.com/mxdx/fs4341.html

随意转载~但请保留教程地址★

标签:php 模版设计模

相关文章

发表留言