首页 > 语言 > PHP > 正文

php 模版设计模

2024-09-04 11:43:43
字体:大 中 小
来源:转载
供稿:网友

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

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

  1. /*  
  2.  *系统服务类 
  3.  */ 
  4. class server { 
  5.     //获取的服务项目列表 
  6.     protected $sl = array('apache'=>'httpd.exe','nginx'=>'nginx.exe','memcache'=>'memcached.exe'); 
  7.     protected $select = '服务key'; 
  8.     //获取服务列表 
  9.     public function getlist() 
  10.     { 
  11.         return $this->sl; 
  12.     } 
  13.     //启动服务操作 
  14.     public function start() 
  15.     { 
  16.         start $this->select; 
  17.     } 
  18.     //停止服务操作 
  19.     public function stop() 
  20.     { 
  21.         stop $this->select; 
  22.     } 
  23.     //重起服务 
  24.     public function reboot() 
  25.     { 
  26.         reboot $this->select; 
  27.     } 
  28.     //选择要操作的服务 
  29.     public function setselect($name) 
  30.     { 
  31.         $this->select = $this->sl[$name]; 
  32.     } 
  33. } 
  34. //显示界面 
  35. class wxpython extends server{ 
  36.   public function __construct() 
  37.   { 
  38.     parent::__construct(); 
  39.   } 
  40.   //窗体 
  41.   public function window() 
  42.   { 
  43.    //生成一个表格,提供给用户选择服务 
  44.     $this->table($this->getlist()); 
  45.     //生成一个启动按钮,他的点击时间为启动服务 
  46.     $this->startbut->bind('onclick',$this->start()); //启动 
  47.     $this->stopbut->bind('onclick',$this->stop());   //关闭 
  48.     $this->rebootbut->bind('onclick',$this->reboot()); //重起 
  49.   }//开源代码Vevb.com 
  50.   //行选择的时候  
  51.   public function rowsonselect() 
  52.   { 
  53.     $this->setselect( $this->tableselect() ); 
  54.   } 
  55. } 

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

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表