laruence / yaf

Fast php framework written in c, built in php extension
http://pecl.php.net/package/yaf
Other
4.52k stars 1.37k forks source link

yaf_view 版本兼容问题 #562

Closed forthxu closed 2 years ago

forthxu commented 3 years ago

自己创建的继承视图,在3.1.4正常,在3.3.3出现一下问题

  1. 安装igbinary扩展,当类内部有变量会报错,下掉igbinary扩展之后正常

2021/11/25 17:10:47 [error] 74701#0: *1 kevent() reported about an closed connection (54: Connection reset by peer) while reading response header from upstream, client: 127.0.0.1

  1. 无法调用内部变量,当模板中调用displayWidget会出错

    //类似视图类
    class View extends \Yaf\View\Simple {
    protected $_test;//扩展冲突
    
    public function get_tpl_vars() {
      return $this->tpl_vars;//变量为null
    }
    
    /**
    @param $widget string 视图插件
    @param $viewPath string 视图插件模板
    @param $vars array 传递变量
    @param $data array 返回值
    */
    public function displayWidget($widget, $viewPath, $vars=array(), &$data = array()) {
      if (!$viewPath) {
          throw new \Exception('部件模板路径不能为空', 500);
      }
      //创建视图
      $config  = \Yaf\Registry::get('config');
      $applicationPath = $config->get('application.directory');
      $tpl_dir = $applicationPath . 'views';
      $view = new \Ku\View($tpl_dir);
      //实现逻辑,并赋值到$vars
      //$widgetClass = '\Business\Widget\'.$widget;
      //$widgetBs = new $widgetClass;
      //赋值模板变量
      foreach($vars as $key => $value) {
          $view->assign($key, $value);
      }
      //渲染
      $config  = \Yaf\Registry::get('config');
      $ext = $config->get('application.view.ext');
      echo $this->getView()->render($viewPath.'.'.$ext);
    
      if (func_num_args() > 4) {
          $data = $view->get_tpl_vars();
      }
    }
    }

public function displayWidget($viewPath, $widgetName, $vars = array(), $tplVars = array(), &$data = array()) {

laruence commented 2 years ago

不要直接访问tpl_vars,可以通过

$view->get();

获取到所有的变量。