本文整理汇总了PHP中SS_HTTPRequest::setRouteParams方法的典型用法代码示例。如果您正苦于以下问题:PHP SS_HTTPRequest::setRouteParams方法的具体用法?PHP SS_HTTPRequest::setRouteParams怎么用?PHP SS_HTTPRequest::setRouteParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SS_HTTPRequest
的用法示例。
在下文中一共展示了SS_HTTPRequest::setRouteParams方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getHTTPRequest
protected function getHTTPRequest($method = 'GET', $class = 'ApiTest_Book', $id = '', $params = array())
{
$request = new SS_HTTPRequest($method, 'api/' . $class . '/' . $id, $params);
$request->match($this->url_pattern);
$request->setRouteParams(array('Controller' => 'RESTfulAPI'));
return $request;
}
示例2: handleRequest
/**
* Handle an HTTP request, defined with a SS_HTTPRequest object.
*
* @param SS_HTTPRequest $request
* @param Session $session
* @param DataModel $model
*
* @return SS_HTTPResponse|string
*/
protected static function handleRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
{
$rules = Config::inst()->get('Director', 'rules');
if (isset($_REQUEST['debug'])) {
Debug::show($rules);
}
foreach ($rules as $pattern => $controllerOptions) {
if (is_string($controllerOptions)) {
if (substr($controllerOptions, 0, 2) == '->') {
$controllerOptions = array('Redirect' => substr($controllerOptions, 2));
} else {
$controllerOptions = array('Controller' => $controllerOptions);
}
}
if (($arguments = $request->match($pattern, true)) !== false) {
$request->setRouteParams($controllerOptions);
// controllerOptions provide some default arguments
$arguments = array_merge($controllerOptions, $arguments);
// Find the controller name
if (isset($arguments['Controller'])) {
$controller = $arguments['Controller'];
}
// Pop additional tokens from the tokenizer if necessary
if (isset($controllerOptions['_PopTokeniser'])) {
$request->shift($controllerOptions['_PopTokeniser']);
}
// Handle redirection
if (isset($arguments['Redirect'])) {
return "redirect:" . Director::absoluteURL($arguments['Redirect'], true);
} else {
Director::$urlParams = $arguments;
$controllerObj = Injector::inst()->create($controller);
$controllerObj->setSession($session);
try {
$result = $controllerObj->handleRequest($request, $model);
} catch (SS_HTTPResponse_Exception $responseException) {
$result = $responseException->getResponse();
}
if (!is_object($result) || $result instanceof SS_HTTPResponse) {
return $result;
}
user_error("Bad result from url " . $request->getURL() . " handled by " . get_class($controllerObj) . " controller: " . get_class($result), E_USER_WARNING);
}
}
}
// No URL rules matched, so return a 404 error.
return new SS_HTTPResponse('No URL rule was matched', 404);
}
示例3: handleRequest
/**
* Handle an HTTP request, defined with a SS_HTTPRequest object.
*
* @return SS_HTTPResponse|string
*/
protected static function handleRequest(SS_HTTPRequest $request, Session $session, DataModel $model)
{
$rules = Config::inst()->get('Director', 'rules');
if (isset($_REQUEST['debug'])) {
Debug::show($rules);
}
foreach ($rules as $pattern => $controllerOptions) {
if (is_string($controllerOptions)) {
if (substr($controllerOptions, 0, 2) == '->') {
$controllerOptions = array('Redirect' => substr($controllerOptions, 2));
} else {
$controllerOptions = array('Controller' => $controllerOptions);
}
}
if (($arguments = $request->match($pattern, true)) !== false) {
$request->setRouteParams($controllerOptions);
// controllerOptions provide some default arguments
$arguments = array_merge($controllerOptions, $arguments);
// Find the controller name
if (isset($arguments['Controller'])) {
$controller = $arguments['Controller'];
}
// Pop additional tokens from the tokeniser if necessary
if (isset($controllerOptions['_PopTokeniser'])) {
$request->shift($controllerOptions['_PopTokeniser']);
}
// Handle redirections
if (isset($arguments['Redirect'])) {
return "redirect:" . Director::absoluteURL($arguments['Redirect'], true);
} else {
Director::$urlParams = $arguments;
$controllerObj = Injector::inst()->create($controller);
$controllerObj->setSession($session);
try {
$result = $controllerObj->handleRequest($request, $model);
} catch (SS_HTTPResponse_Exception $responseException) {
$result = $responseException->getResponse();
}
if (!is_object($result) || $result instanceof SS_HTTPResponse) {
return $result;
}
user_error("Bad result from url " . $request->getURL() . " handled by " . get_class($controllerObj) . " controller: " . get_class($result), E_USER_WARNING);
}
}
}
/**
* @andrelohmann
*
* This code allows to return custom Error Pages without using the CMS Module
*
*/
$template = array('ErrorPage', 'Page');
$result = new ArrayData(array('Title' => 404, 'Content' => DBField::create_field('HTMLText', 'No URL rule was matched')));
// No URL rules matched, so return a 404 error.
return new SS_HTTPResponse($result->renderWith($template), 404);
/**
* Original Code
*
* // No URL rules matched, so return a 404 error.
* return new SS_HTTPResponse('No URL rule was matched', 404);
*
*/
}
开发者ID:helpfulrobot,项目名称:andrelohmann-silverstripe-framework-errorpage-patch,代码行数:68,代码来源:Director.php