初始化
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
namespace core\base;
|
||||
|
||||
/**
|
||||
* 视图类
|
||||
*/
|
||||
class View
|
||||
{
|
||||
protected $_controller;
|
||||
protected $_action;
|
||||
protected $_vars = array();
|
||||
|
||||
public function __construct($controller, $action)
|
||||
{
|
||||
$this->_controller = $controller;
|
||||
$this->_action = $action;
|
||||
}
|
||||
|
||||
// 分配变量
|
||||
public function assign($name, $value)
|
||||
{
|
||||
$this->_vars[$name] = $value;
|
||||
}
|
||||
|
||||
// 渲染视图
|
||||
public function render()
|
||||
{
|
||||
extract($this->_vars);
|
||||
$viewFile = APP_PATH . 'app/views/' . $this->_controller . '/' . $this->_action . '.php';
|
||||
|
||||
if (is_file($viewFile)) {
|
||||
include $viewFile;
|
||||
} else {
|
||||
exit('视图文件不存在');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user