php 模版设计模
这个模版,不是smarty的那种模版引擎,不是template。,是一种面向对象设计模式方法,使用的地方譬如,作品easerver中,ui部分用的是wxpython,我现在想换成qt,感觉模版在这种功能就能起到一些作用.
重点是,核心功能封装于主类,让子类去继承应用,程序以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()); //重起 } //开源代码phpfensi测试数据 //行选择的时候 public function rowsonselect() { $this ->setselect( $this ->tableselect() ); } }这样看来,如果我想换qt的操作界面,只需要把wxpython 换成pyqt的界面生成,一样是几个按钮,给他们指定事件就可以了.
或许指定的语法不一样,比如wxpython用 bind指定事件,qt库就不是,更换ui库不需要修改内核功能部分.
查看更多关于php 模版设计模 - php面向对象的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did29627