viewaction_class.php
1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* Tiny - A PHP Framework For Web Artisans
* @author Tiny <tinylofty@gmail.com>
* @copyright Copyright(c) 2010-2014 http://www.tinyrise.com All rights reserved
* @version 1.0
*/
/**
* 视图Action
*
* @author Tiny
* @class ViewAction
*/
class ViewAction extends BaseAction
{
private $viewParam = 'view';
private $defaultView = 'index';
private $view;
private $basePath = 'pages';
private $layout;
private $viewPath=null;
/**
* 设置视图路径
*
* @access public
* @param mixed $viewName
*/
public function setViewPath($viewName)
{
$this->viewPath = $viewName;
}
/**
* 取得视图路径
*
* @access public
* @return String
*/
public function getViewPath()
{
if($this->viewPath === null)
{
if(!is_null(Req::args($this->viewParam))) $this->resolveView(Req::args($this->viewParam));
else $this->viewPath = strtolower($this->getController()->id).DIRECTORY_SEPARATOR.strtr($this->id,'.','/');
}
return $this->viewPath;
}
/**
* 解析视图
*
* @access public
* @param mixed $viewPath
* @return mixed
*/
public function resolveView($viewPath)
{
if(preg_match('/^\w[\w\.\-]*$/',$viewPath))
{
$view = strtr($viewPath,'.','/');
if(!empty($this->basePath)) $view = $this->basePath.'/'.$view;
if($this->getController()->resolveViewFile($view) !== false)
{
$this->view = $view;
return;
}
}
}
/**
* 错误视图action运行入口
*
* @access public
* @return mixed
*/
public function run()
{
//$this->resolveView($this->getViewPath());
$controller = $this->getController();
$controller->render($this->getId(),$this->getData());
}
}