本文整理汇总了PHP中Bluz\Proxy\Request::getParam方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getParam方法的具体用法?PHP Request::getParam怎么用?PHP Request::getParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bluz\Proxy\Request
的用法示例。
在下文中一共展示了Request::getParam方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testParamManipulation
/**
* Test of params
*/
public function testParamManipulation()
{
Request::setParam('foo', 'bar');
Request::setParam('baz', 'qux');
$this->assertEquals('bar', Request::getParam('foo'));
$this->assertEquals('qux', Request::getParam('baz'));
$this->assertEquals('moo', Request::getParam('qux', 'moo'));
$this->assertEqualsArray(['foo' => 'bar', 'baz' => 'qux'], Request::getParams());
$this->assertEqualsArray(['foo' => 'bar', 'baz' => 'qux'], Request::getAllParams());
}
示例2: __construct
/**
* Prepare request for processing
*/
public function __construct()
{
// rewrite REST with "_method" param
// this is workaround
$this->method = strtoupper(Request::getParam('_method', Request::getMethod()));
// get all params
$query = Request::getQuery();
if (is_array($query) && !empty($query)) {
unset($query['_method']);
$this->params = $query;
}
$this->data = Request::getParams();
}
示例3: process
/**
* Response as JSONP
*/
public function process()
{
// override response code so javascript can process it
$this->response->setHeader('Content-Type', 'application/javascript');
// prepare body
if ($body = $this->response->getBody()) {
// convert to JSON
$body = json_encode($body);
// try to guess callback function name
// - check `callback` param
// - check `jsonp` param
// - use `callback` as default callback name
$callback = Request::getParam('jsonp', Request::getParam('callback', 'callback'));
$body = $callback . '(' . $body . ')';
// setup content length
$this->response->setHeader('Content-Length', strlen($body));
// prepare to JSON output
$this->response->setBody($body);
}
}
示例4: function
* Grid of Media
*
* @author Anton Shevchuk
*/
/**
* @namespace
*/
namespace Application;
use Bluz\Proxy\Layout;
use Bluz\Proxy\Request;
use Bluz\Proxy\Response;
return function () use($view) {
/**
* @var Bootstrap $this
* @var \Bluz\View\View $view
*/
Layout::setTemplate('dashboard.phtml');
Layout::breadCrumbs([$view->ahref('Dashboard', ['dashboard', 'index']), __('Media')]);
$grid = new Media\Grid();
$countCol = Request::getParam('countCol');
if ($countCol != null) {
Response::setCookie("countCol", $countCol, time() + 3600, '/');
} else {
$countCol = Request::getCookie('countCol', 4);
}
$lnCol = (int) (12 / $countCol);
$view->countCol = $countCol;
$view->col = $lnCol;
$view->grid = $grid;
};
示例5: processRequest
/**
* Process request
*
* Example of request url
* - http://domain.com/pages/grid/
* - http://domain.com/pages/grid/page/2/
* - http://domain.com/pages/grid/page/2/order-alias/desc/
* - http://domain.com/pages/grid/page/2/order-created/desc/order-alias/asc/
*
* with prefix for support more than one grid on page
* - http://domain.com/users/grid/users-page/2/users-order-created/desc/
* - http://domain.com/users/grid/users-page/2/users-filter-status/active/
*
* hash support
* - http://domain.com/pages/grid/#/page/2/order-created/desc/order-alias/asc/
*
* @return Grid
*/
public function processRequest()
{
$this->module = Request::getModule();
$this->controller = Request::getController();
$page = Request::getParam($this->prefix . 'page', 1);
$this->setPage($page);
$limit = Request::getParam($this->prefix . 'limit', $this->limit);
$this->setLimit($limit);
foreach ($this->allowOrders as $column) {
$order = Request::getParam($this->prefix . 'order-' . $column);
if ($order) {
$this->addOrder($column, $order);
}
}
foreach ($this->allowFilters as $column) {
$filter = Request::getParam($this->prefix . 'filter-' . $column);
if ($filter) {
if (strpos($filter, '-')) {
$filter = trim($filter, ' -');
while ($pos = strpos($filter, '-')) {
$filterType = substr($filter, 0, $pos);
$filter = substr($filter, $pos + 1);
if (strpos($filter, '-')) {
$filterValue = substr($filter, 0, strpos($filter, '-'));
$filter = substr($filter, strpos($filter, '-') + 1);
} else {
$filterValue = $filter;
}
$this->addFilter($column, $filterType, $filterValue);
}
} else {
$this->addFilter($column, self::FILTER_EQ, $filter);
}
}
}
return $this;
}
示例6: function
* @accept HTML
* @accept JSON
* @privilege Management
*
* @param int $id
* @return bool
* @throws Exception
*/
return function ($id) {
/**
* @var Controller $this
*/
$user = Users\Table::findRow($id);
if (!$user) {
throw new Exception('User ID is incorrect');
}
if (Request::isPost()) {
$roles = Request::getParam('roles');
// update roles
Db::delete('acl_users_roles')->where('userId = ?', $user->id)->execute();
foreach ($roles as $role) {
Db::insert('acl_users_roles')->set('userId', $user->id)->set('roleId', $role)->execute();
}
// clean cache
Cache::delete('user:' . $user->id);
Messages::addSuccess('User roles was updated');
return false;
}
$this->assign('user', $user);
$this->assign('roles', Roles\Table::getInstance()->getRoles());
};
示例7: function
* @accept JSON
* @method GET
*
* @param \Bluz\Crud\Table $crud
* @param mixed $primary
* @return array
*/
return function ($crud, $primary) {
if (!empty($primary)) {
// @throws NotFoundException
return [$crud->readOne($primary)];
} else {
$params = Request::getParams();
// setup default offset and limit - safe way
$offset = Request::getParam('offset', 0);
$limit = Request::getParam('limit', 10);
if ($range = Request::getHeader('Range')) {
list(, $offset, $last) = preg_split('/[-=]/', $range);
// for better compatibility
$limit = $last - $offset;
}
Response::setStatusCode(206);
$total = 0;
$result = $crud->readSet($offset, $limit, $params, $total);
if (sizeof($result) < $total) {
Response::setStatusCode(206);
Response::setHeader('Content-Range', 'items ' . $offset . '-' . ($offset + sizeof($result)) . '/' . $total);
}
return $result;
}
};
示例8: testGet
/**
* Complex test for magic getter
*
* @covers \Bluz\Http\Request::getParam()
*/
public function testGet()
{
$this->assertEquals('get', Request::getParam('get'));
$this->assertEquals('post', Request::getParam('post'));
$this->assertEquals('cookie', Request::getParam('cookie'));
$this->assertEquals('server', Request::getParam('server'));
$this->assertEquals('env', Request::getParam('env'));
$this->assertNull(Request::getParam('some'));
}
示例9: function
* @param string $id
*
* @route /api/{$resource}
* @param string $resource
*
* @return mixed
*/
return function ($resource, $id, $relation, $relationId) {
/**
* @var Controller $this
*/
$this->useJson();
Auth::clearIdentity();
try {
// authentication by api token
if ($token = Request::getParam('token')) {
Table::getInstance()->authenticateToken($token);
}
$params = [];
foreach ([$id, $relation, $relationId] as $param) {
if (!is_null($param)) {
$params[] = $param;
}
}
return $this->dispatch('api', 'resources/' . $resource, $params);
} catch (\Exception $e) {
// process exceptions here
Response::setStatusCode($e->getCode());
return ['error' => $e->getMessage()];
}
};
示例10: function
<?php
/**
* Created by PhpStorm.
* User: gunko
* Date: 9/29/15
* Time: 10:22 AM
*/
/**
* @namespace
*/
namespace Application;
use Bluz\Controller;
use Bluz\Proxy\Request;
return function () {
$str = Request::getParam('query');
if ($str != NULL) {
return $search = \Application\MusicTypes\Table::getInstance()->search($str);
} else {
return [];
}
};