这个模版,不是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());
- }
-
- public function rowsonselect()
- {
- $this->setselect( $this->tableselect() );
- }
- }
这样看来,如果我想换qt的操作界面,只需要把wxpython 换成pyqt的界面生成,一样是几个按钮,给他们指定事件就可以了.
或许指定的语法不一样,比如wxpython用 bind指定事件,qt库就不是,更换ui库不需要修改内核功能部分. |