本文整理汇总了PHP中SS_HTTPRequest::setUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP SS_HTTPRequest::setUrl方法的具体用法?PHP SS_HTTPRequest::setUrl怎么用?PHP SS_HTTPRequest::setUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SS_HTTPRequest
的用法示例。
在下文中一共展示了SS_HTTPRequest::setUrl方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleUpload
/**
* The endpoint for file uploads. Hands off to Dropzone module
*
* @param SS_HTTPRequest $r
* @return SS_HTTPResponse
*/
public function handleUpload(SS_HTTPRequest $r)
{
$r->setUrl('upload');
$folder = Folder::get()->byID($r->param('FolderID'));
$uploader = FileAttachmentField::create('dummy');
if ($folder) {
$uploader->setFolderName(self::remove_assets_dir($folder->Filename));
} else {
$uploader->setFolderName('/');
}
$httpResponse = $uploader->handleRequest($r, DataModel::inst());
if ($httpResponse->getStatusCode() !== 200) {
return $httpResponse;
}
$ids = $httpResponse->getBody();
$files = File::get()->byIDs(explode(',', $ids));
$response = array();
foreach ($files as $f) {
$response[] = $this->createFileJSON($f, $folder);
}
return (new SS_HTTPResponse(Convert::array2json($response)))->addHeader('Content-Type', 'application/json');
}
示例2: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
self::$is_at_root = true;
$this->setDataModel($model);
$this->pushCurrent();
$this->init();
if ($language = $request->param('Language')) {
if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
//Language is missing a dash 404
if (strpos($language, '-') === false) {
//Locale not found 404
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
return $this->response;
}
$locale = explode('-', $language);
$locale[1] = strtoupper($locale[1]);
//Make sure that the language is all lowercase
if ($language == implode('-', $locale)) {
//Locale not found 404
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
return $this->response;
}
$locale = implode('_', $locale);
} else {
$locale = $language;
}
} else {
if (strpos($request->param('Language'), '_') !== false) {
//Locale not found 404
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
return $this->response;
} else {
$locale = i18n::get_locale_from_lang($language);
}
}
if (in_array($locale, Translatable::get_allowed_locales())) {
Cookie::set('language', $language);
Translatable::set_current_locale($locale);
i18n::set_locale($locale);
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse();
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->response;
}
$request->setUrl($language . '/' . self::get_homepage_link() . '/');
$request->match('$Language/$URLSegment//$Action', true);
$controller = new MultilingualModelAsController();
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
} else {
//URL Param Locale is not allowed so redirect to default
$this->redirect(Controller::join_links(Director::baseURL(), Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL') ? Translatable::default_locale() : Translatable::default_lang()) . '/', 301);
$this->popCurrent();
return $this->response;
}
}
//No Locale Param so detect browser language and redirect
if ($locale = self::detect_browser_locale()) {
if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
$language = str_replace('_', '-', strtolower($locale));
} else {
$language = $locale;
}
} else {
$language = i18n::get_lang_from_locale($locale);
}
Cookie::set('language', $language);
$this->redirect(Controller::join_links(Director::baseURL(), $language) . '/', 301);
$this->popCurrent();
return $this->response;
}
if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
$language = str_replace('_', '-', strtolower(Translatable::default_locale()));
} else {
$language = Translatable::default_locale();
}
} else {
$language = Translatable::default_lang();
}
$this->redirect(Controller::join_links(Director::baseURL(), $language . '/'), 301);
$this->popCurrent();
return $this->response;
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:99,代码来源:MultilingualRootURLController.php
示例3: handleManage
/**
* Hand off presentation CRUD to a sub controller. Ensure the user
* can write to the presentation first
* @param $r SS_HTTPRequest
* @return RequestHandler
*/
public function handleManage(SS_HTTPRequest $r)
{
$summit = $this->Summit();
if (is_null($summit) || !$summit->exists() || !$this->presentation_manager->isPresentationEditionAllowed(Member::currentUser(), $summit)) {
$r->setUrl($this->Link());
//clean up dir parts so we could redirect without 404
return $this->redirect($this->Link(), 301);
}
$presentation_id = Convert::raw2sql($r->param('PresentationID'));
$presentation = $presentation_id === 'new' ? Presentation::create() : Presentation::get()->byID($presentation_id);
if (!$presentation) {
return $this->httpError(404);
}
if ($presentation->isInDB() && !$this->canEditPresentation($presentation->ID)) {
return $this->httpError(403, "You can't edit this presentation");
}
if (!$presentation->isInDB() && !$presentation->canCreate()) {
return $this->httpError(403);
}
$request = PresentationPage_ManageRequest::create($presentation, $this);
return $request->handleRequest($r, DataModel::inst());
}
示例4: handleRequest
/**
* @param SS_HTTPRequest $request
* @param DataModel|null $model
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
self::$is_at_root = true;
$this->setDataModel($model);
$this->pushCurrent();
$this->init();
if (!DB::is_active() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse();
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->response;
}
$request->setUrl(self::get_homepage_link() . '/');
$request->match('$URLSegment//$Action', true);
$controller = new ModelAsController();
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
}