<?php
namespace app;

class View
{
    public $assign;#用于判断类是否存在，节约性能

    /**
     * 变量名替换
     * @param $name
     * @param $value
     */
    public function assign($name,$value)
    {
        $this->assign[$name] = $value;
    }
 
    /**
     * 显示视图
     * @param $file
     */
    // public function display($file)
    // {
    //     $file = APP.'/views/'.$file;
    //     if (is_file($file)){
    //         extract($this->assign);#从数组中将变量导入到当前的符号表
    //         include $file;
    //     }
    // }

    public function fetch($file = ""){
        // var_dump($this->assign);
        // exit;
        if (!empty($this->assign)) {
            extract($this->assign);
        }
        if ($file) {
            $filename = ROOT_PATH ."html" . DS . $file;
        } else {
            $filename = ROOT_PATH ."html" . DS . $GLOBALS['action'] . '.html';
        }
        return require($filename);
    }
}