AbstractAction.php 1.6 KB
<?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);
        }
    }

}