MixMVC为了在整个请求流程中,添加MVC相关的一些参数又不想污染全局的$_GET,$_POST,$_REQUEST对象,所以重新将$_GET,$_POST,$_REQUEST封装成MST_ActionController_Request对象。MST_ActionController_Router会根据请求的URL,将MVC的相关参数填充到MST_ActionController_Request之中,在Controller及View中,都可以通过$this->params 变量获取MST_ActionController_Request对象。
预定义参数
MST_ActionController_Request的预定义参数需要使用类属性的方式获取,使用array的[key_name]方式获取参数将会报错。
class IndexController extends MST_ActionController { public function indexAction() { $this->params->get; //获取$_GET $this->params->post; //获取$_POST $this->params->files; //获取$_FILES } }
预定义函数
MST_ActionController_Request预定义了一些的函数,去简化了一下流程。
class IndexController extends MST_ActionController { public function indexAction() { $this->params->getRequestIp(); //获取请求IP(字符串格式 如:192.168.33.1) $this->params->getRequestIp(true); //获取请求IP(整形格式) $this->params->isPost('register'); //判断POST提交,配合MST_Core::generateValidCode($prefix)使用,用于验证请求来源,防止恶意提交 $this->params->isAjax(); //判断是否Ajax请求 $this->params->isFlash(); //判断是否Flash请求 } }
发表评论
要发表评论,您必须先登录。