AbstractAction.php
1.6 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
85
86
87
<?php
/**
* 所有Controller控制器的基类
*
* @name AbstractAction
* @package
* @copyright yoho.inc
* @version 1.0 (2015-9-15 11:55:25)
* @author fei.hong <fei.hong@yoho.cn>
*/
namespace Action;
use Yaf\Controller_Abstract;
use Yaf\Dispatcher;
use Hood\Cache;
class AbstractAction extends Controller_Abstract
{
/**
* HTTP请求对象
*
* @var object
*/
protected $_request;
/**
* 初始化
*/
public function init()
{
$this->_request = $this->getRequest();
}
/**
* 封装一下获取get参数
*
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function get($key, $default = null)
{
return $this->_request->getQuery($key, $default);
}
/**
* 封装一下获取post参数
*
* @param String $key
* @param mixed $default
* @return mixed
*/
protected function post($key, $default = null)
{
return $this->_request->getPost($key, $default);
}
/**
* 关闭模板自动渲染
*
* @return void
*/
protected function disableView()
{
Dispatcher::getInstance()->autoRender(false);
}
/**
* 使用Memcache缓存
*
* @param string $node
* @param string $childNode
* @return object
*/
protected function memcache($node = null, $childNode = 'hosts')
{
if (PATH_SEPARATOR === '\\') {
return Cache::memcache($node, $childNode);
} else {
return Cache::memcached($node, $childNode);
}
}
}