发新话题
打印

参考ZF设计个简单的viewer

参考ZF设计个简单的viewer

昨天开始着手PHPBEAN的设计,PHPBEAN定位为zend Framework的PHP4版本。

  考虑执行的效率,没有使用模版技术,个人感觉采用DISCUZ或者其他的模版的技术并没有什么好处,对于美工来说和{test}有很大区别吗?而且还降低了效率(关于discuz的模版原理,具体参考这里),虽然说采用首次缓存成PHP速度就一样了,但俺觉得还实多此一举。

  所以,这个简单的viewer具有基本的zf里面的viewer功能,而且考虑ZF使用人员的习惯,命名也和ZF的VIEWER一样。个人感觉相对ZF的VIEWER来说,有一个好处:简化、提高了效率。
复制内容到剪贴板
代码:
<?
class viewer
{
     
    var $path;
     
    function __construct($path='')
    {
       if(!empty($path))$this->set_tpl_path($path);
    }
     
    function set_tpl_path($path)
    {
       if(!file_exists($path))$this->error(1,$path);
       $this->path=$path;
    }
     
    function render($template)
    {
       if(!file_exists($this->path.$template))$this->error(2,$this->path.$template);
       ob_start();
       require $this->path.$template;
       return ob_get_clean();
    }
     
    /*--------私有方法----------------------*/
     
    function error($id,$other='')
    {
       switch($id)
       {
          case 1:
             $errormsg=$other.' 不是有效的文件路径!';
             break;
          case 2:
             $errormsg=$other.' 不是有效的模版文件!';
             break;
          default:
             break;      
       }
       die($errormsg);   
    }     
}
?>
代码很简单,没写注释了,也没写使用实例,应该熟悉ZF的使用实一点问题都没有。
一個偽裝成白癡的天纔!

TOP

发新话题