HEX
Server: Apache/2.4.6 (CentOS) PHP/5.6.39
System: Linux izj6c6ukj0hyugxsgmuxz3z 3.10.0-514.6.2.el7.x86_64 #1 SMP Thu Feb 23 03:04:39 UTC 2017 x86_64
User: root (0)
PHP: 5.6.39
Disabled: NONE
Upload Files
File: /web/data/www.tbbprovision.com/lib/View.class.php
<?php
/**
 * 视图基类
 */

class View
{
    protected $variables = array();
    protected $_controller;
    protected $_action;
    protected $_module;

    function __construct($controller, $action, $module)
    {
        $this->_controller = $controller;
        $this->_action = str_replace('_action','',$action);
        $this->_module = $module;
    }
 
    // 分配变量
    public function assign($name, $value)
    {
        $this->variables[$name] = $value;
    }
 
    // 渲染显示
    public function render($model_name='',$action_name='',$only_file=0)
    {
        extract($this->variables);
        $view_model = $model_name ? $model_name : $this->_module ;
        $view_file = $action_name ? $action_name : $this->_action ;

        $defaultHeader = APP_PATH . 'application/'.$view_file.'views/header.php';
        $defaultFooter = APP_PATH . 'application/'.$view_file.'views/footer.php';
        $defaultLayout = APP_PATH . 'application/'.$view_file.'views/layout.php';

        $controllerHeader = APP_PATH . 'application/'.$view_model.'/views/' . 'inc/header.php';
        $controllerFooter = APP_PATH . 'application/'.$view_model.'/views/' . 'inc/footer.php';
        $controllerLayout = APP_PATH . 'application/'.$view_model.'/views/' . strtolower($this->_controller) . '/' . $view_file . '.php';

        // 页头文件
        if (!$only_file && file_exists($controllerHeader)) {
            include ($controllerHeader);
        } else {
            //include ($defaultHeader);
        }

        // 页内容文件
        if (file_exists($controllerLayout)) {
            include ($controllerLayout);
        } else {
            //include ($defaultLayout);
        }
        
        // 页脚文件
        if (!$only_file && file_exists($controllerFooter)) {
            include ($controllerFooter);
        } else {
            //include ($defaultFooter);
        }
    }

    public static function page_404()
    {
        include(APP_PATH.'/404.html');
        exit;
    }
}