本文整理汇总了PHP中Zend_Controller_Request_Abstract::setParam方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Controller_Request_Abstract::setParam方法的具体用法?PHP Zend_Controller_Request_Abstract::setParam怎么用?PHP Zend_Controller_Request_Abstract::setParam使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Controller_Request_Abstract
的用法示例。
在下文中一共展示了Zend_Controller_Request_Abstract::setParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: routeShutdown
/**
* routeShutdown
* 在 路由器 完成请求的路由后被调用
* @param Zend_Controller_Request_Abstract $request
* @return void
*/
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
/**
* 检测请求的Content-type类型
*/
$pathinfo = $request->getPathInfo();
if (!empty($pathinfo)) {
if ($extension = pathinfo($pathinfo, PATHINFO_EXTENSION)) {
if (preg_match('/^[-a-z0-9]+$/i', $extension)) {
$request->setParam(static::KEY_EXT, strtolower($extension));
}
}
}
/**
* 检测是否支持json响应
*/
if ($request->getParam(static::KEY_EXT) == '') {
$accept = $request->getServer('HTTP_ACCEPT');
if (!empty($accept)) {
if (strpos($accept, 'json') !== false) {
$request->setParam(static::KEY_EXT, 'json');
}
}
}
/**
* 格式化请求目标信息,不允许[-a-zA-Z0-9]以外的字符
*/
$pattern = '/[^-a-zA-Z0-9].*/';
$request->setModuleName(preg_replace($pattern, '', $request->getModuleName()));
$request->setControllerName(preg_replace($pattern, '', $request->getControllerName()));
$request->setActionName(preg_replace($pattern, '', $request->getActionName()));
}
示例2: route
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
try {
$getopt = new Zend_Console_Getopt(array('verbose|v' => 'Print verbose output', 'file|f=s' => 'File to upload'));
$getopt->parse;
$arguments = $getopt->getRemainingArgs();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
if ($arguments) {
$command = array_shift($arguments);
$action = array_shift($arguments);
if (!preg_match('~\\W~', $command)) {
$dispatcher->setControllerName($command);
$dispatcher->setActionName($action);
$dispatcher->setParams($arguments);
if (isset($getopt->v)) {
$dispatcher->setParam('verbose', true);
}
if (isset($getopt->f)) {
$dispatcher->setParam('file', $getopt->f);
}
return $dispatcher;
}
echo "Invalid command.\n", exit;
}
echo "No command given.\n", exit;
}
示例3: getRequest
/**
* Retrieves the request object
*
* @return Zend_Controller_Request_Abstract
*/
public function getRequest()
{
if (null === $this->_request) {
$options = $this->getOptions();
// Don't instantiate an HTTP request in CLI mode
if (PHP_SAPI == 'cli') {
$this->_request = new Zend_Controller_Request_Simple();
} else {
// Load Apache-specific request object if applicable
$this->_request = function_exists('apache_get_version') ? new Zend_Controller_Request_Apache404() : new Zend_Controller_Request_Http();
}
// Store the config settings, if any, in the request
foreach ($options as $key => $value) {
$method = 'set' . $key;
// E.g. "setBaseUrl", "setParams"
if (method_exists($this->_request, $method)) {
$this->_request->{$method}($value);
} else {
$this->_request->setParam($key, $value);
}
}
// Store the request in the front controller
$this->_bootstrap->bootstrap('FrontController');
$front = $this->_bootstrap->getResource('FrontController');
$front->setRequest($this->_request);
}
return $this->_request;
}
示例4: preDispatch
/**
* @param Zend_Controller_Request_Abstract $oHttpRequest
*/
public function preDispatch(Zend_Controller_Request_Abstract $oHttpRequest)
{
$sControllerName = $oHttpRequest->getControllerName();
$sActionName = $oHttpRequest->getActionName();
$aRequestedParams = $oHttpRequest->getUserParams();
$sQuery = '';
unset($aRequestedParams['controller']);
unset($aRequestedParams['action']);
// Define user role
if (Zend_Auth::getInstance()->hasIdentity()) {
$aData = Zend_Auth::getInstance()->getStorage()->read();
$sRole = $aData['role'];
} else {
// Default role
$sRole = 'guest';
}
// Check access
if (!$this->_oAcl->isAllowed($sRole, $sControllerName, $sActionName)) {
$oHttpRequest->setParam('referer_controller', $sControllerName);
$oHttpRequest->setParam('referer_action', $sActionName);
$aParams = array();
if (count($aRequestedParams)) {
foreach ($aRequestedParams as $sKey => $sValue) {
$aParams[] = $sKey;
$aParams[] = $sValue;
}
$sQuery = implode('/', $aParams) . '/';
}
$oHttpRequest->setParam('query', $sQuery);
$oHttpRequest->setControllerName('auth')->setActionName('login');
$this->_response->setHttpResponseCode(401);
}
}
示例5: dispatchLoopStartup
/**
* @param Zend_Controller_Request_Abstract $request
*/
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
if (!$request instanceof Zend_Controller_Request_Http) {
return;
}
// Accept URI parameter over Accept header for specifying of desired response format
$format = $this->getRequest()->getParam('format') ?: $request->getHeader('Accept');
// @todo Need to look into implementing Accept header supporting multiple types with quality factors
switch (true) {
// XML
case stristr($format, 'text/xml') && !stristr($format, 'html'):
$request->setParam('format', 'xml');
break;
// JSONP/Javascript
// JSONP/Javascript
case stristr($format, 'text/javascript'):
$request->setParam('format', 'js');
break;
// JSON
// JSON
case stristr($format, 'application/json'):
default:
// Note the fall through!
$request->setParam('format', 'json');
break;
}
}
示例6: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
try {
$module = $request->getModuleName();
if ($module == 'admin') {
$moduleList = new Zend_Session_Namespace('moduleList');
$userInfo = new Zend_Session_Namespace('userInfo');
$module = $moduleList->module;
$allowed_module = $userInfo->module_list;
//generating all resources
$acl = new Zend_Acl();
//generating user permission
$acl->addRole(new Zend_Acl_Role('admin'));
$acl->addRole(new Zend_Acl_Role('anonymous'));
$acl->add(new Zend_Acl_Resource('index'));
$acl->add(new Zend_Acl_Resource('ajax'));
$acl->allow('admin', 'index');
$acl->allow('admin', 'ajax');
if (!empty($module)) {
foreach ($module as $value) {
if (!$acl->has($value['controller'])) {
$acl->add(new Zend_Acl_Resource($value['controller']));
}
if (in_array($value['id'], $allowed_module)) {
if ($value['action'] != null) {
$acl->allow('admin', $value['controller'], $value['action']);
} else {
$acl->allow('admin', $value['controller']);
}
}
}
}
//allowing anonymous user to get into the login page
$acl->allow('anonymous', 'index', 'index');
$acl->allow('anonymous', 'index', 'login');
$auth = Zend_Auth::getInstance();
if ($auth->hasIdentity()) {
$role = 'admin';
} else {
$role = 'anonymous';
}
$controller = $request->controller;
$action = $request->action;
if (!$acl->isAllowed($role, $controller, $action)) {
$request->setModuleName('admin');
$request->setControllerName('error');
$request->setActionName('acl');
$request->setParam('type', 1);
}
}
} catch (Zend_Acl_Exception $e) {
$request->setModuleName('admin');
$request->setControllerName('error');
$request->setActionName('acl');
$request->setParam('type', 2);
}
}
示例7: resetObjects
/**
* Reset object states
*
* @return void
*/
public function resetObjects()
{
$params = $this->request->getUserParams();
foreach (array_keys($params) as $key) {
$this->request->setParam($key, null);
}
$this->response->clearBody();
$this->response->clearHeaders()->clearRawHeaders();
}
示例8: dispatchLoopStartup
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
$header = $request->getHeader('Accept');
if (strstr($header, 'application/json')) {
$request->setParam('format', 'json');
} elseif (strstr($header, 'application/xml')) {
$request->setParam('format', 'xml');
} else {
$request->setParam('format', 'html');
}
}
示例9: setCliParamsToDispatcher
/**
* @params \Zend_Controller_Request_Abstract $dispatcher
* @params string $paramString
*/
protected function setCliParamsToDispatcher(\Zend_Controller_Request_Abstract $dispatcher, $paramString)
{
if (!empty($paramString)) {
$decodeFunctions = array('decode_none', 'decode_base64', 'decode_base32', 'decode_base32hex', 'decode_hex');
foreach ($decodeFunctions as $decoder) {
$decodedPararms = $this->{$decoder}($paramString);
if (!empty($decodedPararms) && $this->isJsonString($decodedPararms)) {
$dispatcher->setParam('params', $decodedPararms);
return;
}
}
}
$dispatcher->setParam('params', $paramString);
}
示例10: preDispatch
/**
* Pre dispatch
*
* @author Eddie Jaoude
* @param Zend_Controller_Request_Abstract $request
* @return void
*
*/
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
# get application objects
$_registry = Zend_Registry::getInstance();
# clone objects for ease of use
$_em = $_registry->doctrine->_em;
$_logger = $_registry->logger;
# helper
$_flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');
# send to actions
$request->setParam('_registry', $_registry);
$request->setParam('_em', $_em);
$request->setParam('_logger', $_logger);
$request->setParam('_flashMessenger', $_flashMessenger);
}
开发者ID:MarS2806,项目名称:Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD-,代码行数:23,代码来源:Registry.php
示例11: routeStartup
public function routeStartup(Zend_Controller_Request_Abstract $request)
{
if (substr($request->getRequestUri(), 0, -1) == $request->getBaseUrl()) {
$request->setRequestUri($request->getRequestUri() . Zend_Registry::get('parameters')->registry->defaultlanguage . "/");
$request->setParam("language", Zend_Registry::get('parameters')->registry->defaultlanguage);
}
}
示例12: route
public function route(Zend_Controller_Request_Abstract $dispatcher)
{
$getopt = new Zend_Console_Getopt(array());
$arguments = $getopt->getRemainingArgs();
$controller = 'index';
$action = 'index';
if ($arguments) {
$controller = array_shift($arguments);
if ($arguments) {
$action = array_shift($arguments);
$pattern_valid_action = '~^\\w+[\\-\\w\\d]+$~';
if (false == preg_match($pattern_valid_action, $action)) {
echo "Invalid action {$action}.\n", exit;
}
if ($arguments) {
foreach ($arguments as $arg) {
$parameter = explode('=', $arg, 2);
if (false == isset($parameter[1])) {
$parameter[1] = true;
}
$dispatcher->setParam($parameter[0], $parameter[1]);
unset($parameter);
}
}
}
}
$dispatcher->setControllerName($controller)->setActionName($action);
return $dispatcher;
}
示例13: apply
public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
{
// very small optimization
$catId = (int) Mage::helper('adjnav')->getParam($this->getRequestVar());
if ($catId) {
$request->setParam($this->getRequestVar(), $catId);
parent::apply($request, $filterBlock);
}
$category = $this->getCategory();
if (!Mage::registry('current_category_filter')) {
Mage::register('current_category_filter', $category);
}
if (!isset($filter) || !$filter) {
$this->addCategoryFilter($category, null);
return $this;
}
$this->_appliedCategory = Mage::getModel('catalog/category')->setStoreId(Mage::app()->getStore()->getId())->load($filter);
if ($this->_isValidCategory($this->_appliedCategory)) {
/*
$this->getLayer()->getProductCollection()
->addCategoryFilter($this->_appliedCategory);
*/
$this->addCategoryFilter($this->_appliedCategory, $filter);
$this->getLayer()->getState()->addFilter($this->_createItem($this->_appliedCategory->getName(), $filter));
}
return $this;
}
示例14: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$context = $request->getHeader('X-Zrt-Format');
if ($context) {
$request->setParam('format', $context);
}
}
示例15: preDispatch
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
if ($request->getParam('sid') !== null && $request->getParam('PHPSESSID') === null) {
$request->setParam('PHPSESSID', $request->getParam('sid'));
}
if ($request->getParam('PHPSESSID') === null) {
$module = strtolower($request->getModuleName());
$controller = strtolower($request->getControllerName());
$action = strtolower($request->getActionName());
$route = $module . '/' . $controller . '/' . $action;
if (!in_array($route, $this->_whitelist)) {
if (is_null($this->_auth)) {
$auth = Zend_Auth::getInstance();
$auth->setStorage(new Zend_Auth_Storage_Session($this->getStorage()));
$this->_auth = $auth;
}
if (!$this->_auth->hasIdentity()) {
$errorHandler = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
$errorHandler->type = 'EXCEPTION_NOT_ALLOWED';
$errorHandler->exception = new Zend_Controller_Action_Exception('No credentials available');
$errorHandler->request = clone $request;
$request->setParam('error_handler', $errorHandler)->setModuleName($this->getErrorHandlerModule())->setControllerName($this->getErrorHandlerController())->setActionName($this->getErrorHandlerAction());
} else {
$this->_auth->getIdentity()->connect();
$this->_auth->getIdentity()->refresh();
}
}
}
}