本文整理汇总了PHP中FormField::handleRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP FormField::handleRequest方法的具体用法?PHP FormField::handleRequest怎么用?PHP FormField::handleRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormField
的用法示例。
在下文中一共展示了FormField::handleRequest方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRequest
/**
* Custom request handler that will check component handlers before proceeding to the default implementation.
*
* @todo There is too much code copied from RequestHandler here.
*/
function handleRequest(SS_HTTPRequest $request, DataModel $model) {
if($this->brokenOnConstruct) {
user_error("parent::__construct() needs to be called on {$handlerClass}::__construct()", E_USER_WARNING);
}
$this->request = $request;
$this->setModel($model);
$fieldData = $this->request->requestVar($this->getName());
if($fieldData && $fieldData['GridState']) $this->getState(false)->setValue($fieldData['GridState']);
foreach($this->components as $component) {
if(!($component instanceof GridField_URLHandler)) {
continue;
}
$urlHandlers = $component->getURLHandlers($this);
if($urlHandlers) foreach($urlHandlers as $rule => $action) {
if($params = $request->match($rule, true)) {
// Actions can reference URL parameters, eg, '$Action/$ID/$OtherID' => '$Action',
if($action[0] == '$') $action = $params[substr($action,1)];
if(!method_exists($component, 'checkAccessAction') || $component->checkAccessAction($action)) {
if(!$action) {
$action = "index";
} else if(!is_string($action)) {
throw new LogicException("Non-string method name: " . var_export($action, true));
}
try {
$result = $component->$action($this, $request);
} catch(SS_HTTPResponse_Exception $responseException) {
$result = $responseException->getResponse();
}
if($result instanceof SS_HTTPResponse && $result->isError()) {
return $result;
}
if($this !== $result && !$request->isEmptyPattern($rule) && is_object($result) && $result instanceof RequestHandler) {
$returnValue = $result->handleRequest($request, $model);
if(is_array($returnValue)) {
throw new LogicException("GridField_URLHandler handlers can't return arrays");
}
return $returnValue;
// If we return some other data, and all the URL is parsed, then return that
} else if($request->allParsed()) {
return $result;
// But if we have more content on the URL and we don't know what to do with it, return an error.
} else {
return $this->httpError(404, "I can't handle sub-URLs of a " . get_class($result) . " object.");
}
}
}
}
}
return parent::handleRequest($request, $model);
}
示例2: handleRequest
/**
* Custom request handler that will check component handlers before proceeding to the default
* implementation.
*
* @todo copy less code from RequestHandler.
*
* @param SS_HTTPRequest $request
* @param DataModel $model
*
* @return array|RequestHandler|SS_HTTPResponse|string|void
*
* @throws SS_HTTPResponse_Exception
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
if ($this->brokenOnConstruct) {
user_error(sprintf("parent::__construct() needs to be called on %s::__construct()", __CLASS__), E_USER_WARNING);
}
$this->setRequest($request);
$this->setDataModel($model);
$fieldData = $this->getRequest()->requestVar($this->getName());
if ($fieldData && isset($fieldData['GridState'])) {
$this->getState(false)->setValue($fieldData['GridState']);
}
foreach ($this->getComponents() as $component) {
if ($component instanceof GridField_URLHandler && ($urlHandlers = $component->getURLHandlers($this))) {
foreach ($urlHandlers as $rule => $action) {
if ($params = $request->match($rule, true)) {
// Actions can reference URL parameters.
// e.g. '$Action/$ID/$OtherID' → '$Action'
if ($action[0] == '$') {
$action = $params[substr($action, 1)];
}
if (!method_exists($component, 'checkAccessAction') || $component->checkAccessAction($action)) {
if (!$action) {
$action = "index";
}
if (!is_string($action)) {
throw new LogicException(sprintf('Non-string method name: %s', var_export($action, true)));
}
try {
$result = $component->{$action}($this, $request);
} catch (SS_HTTPResponse_Exception $responseException) {
$result = $responseException->getResponse();
}
if ($result instanceof SS_HTTPResponse && $result->isError()) {
return $result;
}
if ($this !== $result && !$request->isEmptyPattern($rule) && is_object($result) && $result instanceof RequestHandler) {
$returnValue = $result->handleRequest($request, $model);
if (is_array($returnValue)) {
throw new LogicException('GridField_URLHandler handlers can\'t return arrays');
}
return $returnValue;
}
if ($request->allParsed()) {
return $result;
}
return $this->httpError(404, sprintf('I can\'t handle sub-URLs of a %s object.', get_class($result)));
}
}
}
}
}
return parent::handleRequest($request, $model);
}
示例3: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
if ($request->match('addinlinerecord', true)) {
// NOTE(Jake): Handling here as I'm not sure how to do a url_handler that allows
// infinite parameters after 'addinlinerecord'
$result = $this->handleAddInline($request);
if ($result && is_object($result) && $result instanceof RequestHandler) {
// NOTE(Jake): Logic copied from parent::handleRequest()
$returnValue = $result->handleRequest($request, $model);
if ($returnValue && is_array($returnValue)) {
$returnValue = $this->customise($returnValue);
}
return $returnValue;
}
// NOTE(Jake): Consume all remaining parts so that 'RequestHandler::handleRequest'
// doesn't hit an error. (Use Case: Getting an error with a GridField::handleRequest)
// NOTE(Jake): THis is probably due to just CLASSNAME not being consumed/shifted in 'addinlinerecord'
// but cbf changing and re-testing everything.
$dirParts = explode('/', $request->remaining());
foreach ($dirParts as $dirPart) {
$request->shift();
}
return $result;
}
$result = parent::handleRequest($request, $model);
return $result;
}