本文整理汇总了PHP中Bolt\Library::simpleredirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Library::simpleredirect方法的具体用法?PHP Library::simpleredirect怎么用?PHP Library::simpleredirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bolt\Library
的用法示例。
在下文中一共展示了Library::simpleredirect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: passwordForm
/**
* Show the password form. If the visitor gives the correct password, they
* are redirected to the page they came from, if any.
*
* @return \Twig_Markup
*/
public function passwordForm()
{
// Set up the form.
$form = $this->app['form.factory']->createBuilder('form');
if ($this->config['password_only'] == false) {
$form->add('username', 'text');
}
$form->add('password', 'password');
$form = $form->getForm();
if ($this->app['request']->getMethod() == 'POST') {
$form->bind($this->app['request']);
$data = $form->getData();
if ($form->isValid() && $this->checkLogin($data)) {
// Set the session var, so we're authenticated..
$this->app['session']->set('passwordprotect', 1);
$this->app['session']->set('passwordprotect_name', $this->checkLogin($data));
// Print a friendly message..
printf("<p class='message-correct'>%s</p>", $this->config['message_correct']);
$returnto = $this->app['request']->get('returnto');
// And back we go, to the page we originally came from..
if (!empty($returnto)) {
Lib::simpleredirect($returnto);
die;
}
} else {
// Remove the session var, so we can test 'logging off'..
$this->app['session']->remove('passwordprotect');
$this->app['session']->remove('passwordprotect_name');
// Print a friendly message..
if (!empty($data['password'])) {
printf("<p class='message-wrong'>%s</p>", $this->config['message_wrong']);
}
}
}
// Render the form, and show it it the visitor.
$this->app['twig.loader.filesystem']->addPath(__DIR__);
$html = $this->app['twig']->render('assets/passwordform.twig', array('form' => $form->createView()));
return new \Twig_Markup($html, 'UTF-8');
}
示例2: testSimpleRedirectAbort
/**
* @runInSeparateProcess
*/
public function testSimpleRedirectAbort()
{
$app = $this->getApp();
$this->setExpectedException('Symfony\\Component\\HttpKernel\\Exception\\HttpException', "Redirecting to '/test2'.");
$this->expectOutputString("<p>Redirecting to <a href='/test2'>/test2</a>.</p><script>window.setTimeout(function () { window.location='/test2'; }, 500);</script>");
$redirect = Library::simpleredirect('/test2', true);
}
示例3: requireUserPermission
/**
* Check if a user is logged in, and has the proper required permission. If
* not, we redirect the user to the dashboard.
*
* @param string $permission
*
* @return bool True if permission allowed
*/
public function requireUserPermission($permission = 'dashboard')
{
if ($this->app['users']->isAllowed($permission)) {
return true;
} else {
Lib::simpleredirect($this->app['config']->get('general/branding/path'));
return false;
}
}
示例4: slugTreeRecord
public function slugTreeRecord($slug)
{
// Add snippets, since this is a Frontend route.
$this->app['htmlsnippets'] = true;
if (strripos($slug, '/')) {
// find the last "/"" in the slug
//dump($slug);
// dump($this->app['config']);
// dump($this->app['config']->get('data/contenttypes'));
// dump($this->app['config']->get('general/homepage_template'));
// dump(strripos($slug, '/') == strlen($slug));
// dump(strripos($slug, '/'));
// dump(strlen($slug));
$slug = rtrim($slug, '/');
if (in_array($slug, array('blogs', 'locations', 'structures', 'pages', 'blogposts', 'jobs', 'events', 'persons', 'network', 'publications', 'pressreleases', 'projects', 'taskforces', 'homepage', 'footers'))) {
switch ($slug) {
case 'blogs':
//dump('redirect blogs');
\Bolt\Library::simpleredirect('/blogposts');
die;
break;
default:
\Bolt\Library::simpleredirect('/' . $slug);
die;
break;
}
}
}
// $slug = \Bolt\Helpers\String::slug($slug, -1);
$slug = $this->app['slugify']->slugify($slug);
$contenttype = $this->getContenttypeBySlug($slug, true);
$frontend = new Bolt\Controllers\Frontend();
return $frontend->record($this->app, $contenttype, $slug);
}
示例5: redirect
/**
* Redirect the browser to another page.
*
* @param boolean $safe
*
* @return string
*/
public function redirect($path, $safe)
{
// Nope! We're not allowing user-supplied content to issue redirects.
if ($safe) {
return null;
}
Lib::simpleredirect($path);
return '';
}
示例6: simpleForm
/**
* Create a simple Form.
*
* @param string $formname
* @internal param string $name
* @return string
*/
public function simpleForm($formname = "", $with = array())
{
// Make sure that we allow a session cookie for pages with a form. If we don't, the
// form's CSRF token will not work correctly. This might be a temporary fix, depending
// on how we're going to solve the 'cookies in frontend'-issue.
// @see https://github.com/bolt/bolt/issues/3425
$this->app['config']->set('general/cookies_no_frontend', false);
$this->app['twig.loader.filesystem']->addPath(__DIR__);
// Select which form to use..
if (isset($this->config[$formname])) {
$formconfig = $this->config[$formname];
} else {
return "Simpleforms notice: No form known by name '{$formname}'.";
}
// Set the mail configuration for empty fields to the global defaults if they exist
foreach ($this->global_fields as $configkey) {
if (!array_key_exists($configkey, $formconfig) && !empty($this->config[$configkey])) {
$formconfig[$configkey] = $this->config[$configkey];
} elseif (!array_key_exists($configkey, $formconfig) && empty($this->config[$configkey])) {
$formconfig[$configkey] = false;
}
}
// translate labels if labels extension exists
if ($this->labelsenabled) {
$this->labelfields($formconfig);
}
if ($formconfig['debugmode'] == true) {
dump('Building ' . $formname);
dump($formconfig);
}
$message = "";
$error = "";
$sent = false;
$form = $this->app['form.factory']->createNamedBuilder($formname, 'form', null, array('csrf_protection' => $this->config['csrf']));
foreach ($formconfig['fields'] as $name => $field) {
$options = $this->buildField($name, $field, $with, $formname);
// only add known fields with options to the form
if ($options) {
$form->add($name, $options['attr']['type'], $options);
}
}
$form = $form->getForm();
require_once 'recaptcha-php-1.11/recaptchalib.php';
if ('POST' == $this->app['request']->getMethod()) {
if (!$this->app['request']->request->has($formname)) {
// we're not submitting this particular form
if ($formconfig['debugmode'] == true) {
$error .= "we're not submitting this form: " . $formname;
}
$sent = false;
} else {
// ok we're really submitting this form
$isRecaptchaValid = true;
// to prevent ReCaptcha check if not enabled
if ($this->config['recaptcha_enabled']) {
$isRecaptchaValid = false;
// by Default
$resp = recaptcha_check_answer($this->config['recaptcha_private_key'], $this->getRemoteAddress(), $_POST["recaptcha_challenge_field"], $_POST["recaptcha_response_field"]);
$isRecaptchaValid = $resp->is_valid;
}
if ($isRecaptchaValid) {
$form->bind($this->app['request']);
if ($form->isValid()) {
$res = $this->processForm($formconfig, $form, $formname);
if ($res) {
$message = $formconfig['message_ok'];
$sent = true;
// If redirect_on_ok is set, redirect to that page when succesful.
if (!empty($formconfig['redirect_on_ok'])) {
$redirectpage = $this->app['storage']->getContent($formconfig['redirect_on_ok']);
if ($formconfig['debugmode'] == true) {
dump('Redirecting ' . $formconfig['redirect_on_ok']);
dump($redirectpage);
if ($redirectpage) {
dump("Redirect link: " . $redirectpage->link());
} else {
dump("redirectpage is missing for " . $formname);
}
} elseif ($redirectpage) {
return Lib::simpleredirect($redirectpage->link());
} else {
dump("redirectpage is missing for " . $formname);
}
}
} else {
$error = $formconfig['message_technical'];
}
} else {
$error = $formconfig['message_error'];
}
} else {
$error = $this->config['recaptcha_error_message'];
}
//.........这里部分代码省略.........
示例7: editContent
//.........这里部分代码省略.........
if (is_array($value)) {
foreach ($value as $subkey => $subvalue) {
if (gettype($subvalue) == 'object' && get_class($subvalue) == 'Twig_Markup') {
$val[$key][$subkey] = $subvalue->__toString();
}
}
} else {
$val[$key] = $value;
}
}
if (isset($val['datechanged'])) {
$val['datechanged'] = date_format(new \DateTime($val['datechanged']), 'c');
}
$lc = localeconv();
foreach ($contenttype['fields'] as $key => $values) {
switch ($values['type']) {
case 'float':
// Adjust decimal point dependent on locale
if ($lc['decimal_point'] === ',') {
$val[$key] = str_replace('.', ',', $val[$key]);
}
break;
}
}
// unset flashbag for ajax
$app['session']->getFlashBag()->clear('success');
return new JsonResponse($val);
}
}
// No returnto, so we go back to the 'overview' for this contenttype.
// check if a pager was set in the referrer - if yes go back there
$editreferrer = $app['request']->get('editreferrer');
if ($editreferrer) {
Lib::simpleredirect($editreferrer, true);
} else {
return Lib::redirect('overview', array('contenttypeslug' => $contenttype['slug']));
}
} else {
$app['session']->getFlashBag()->add('error', Trans::__('contenttypes.generic.error-saving', array('%contenttype%' => $contenttype['slug'])));
$app['logger.system']->error('Save error: ' . $content->getTitle(), array('event' => 'content'));
}
}
// We're doing a GET
if (!empty($id)) {
$content = $app['storage']->getContent($contenttype['slug'], array('id' => $id));
if (empty($content)) {
return $app->abort(Response::HTTP_NOT_FOUND, Trans::__('contenttypes.generic.not-existing', array('%contenttype%' => $contenttype['slug'])));
}
// Check if we're allowed to edit this content.
if (!$app['users']->isAllowed("contenttype:{$contenttype['slug']}:edit:{$content['id']}")) {
$app['session']->getFlashBag()->add('error', Trans::__('You do not have the right privileges to edit that record.'));
return Lib::redirect('dashboard');
}
} else {
// Check if we're allowed to create content.
if (!$app['users']->isAllowed("contenttype:{$contenttype['slug']}:create")) {
$app['session']->getFlashBag()->add('error', Trans::__('You do not have the right privileges to create a new record.'));
return Lib::redirect('dashboard');
}
$content = $app['storage']->getEmptyContent($contenttype['slug']);
}
$oldStatus = $content['status'];
$allStatuses = array('published', 'held', 'draft', 'timed');
$allowedStatuses = array();
foreach ($allStatuses as $status) {
if ($app['users']->isContentStatusTransitionAllowed($oldStatus, $status, $contenttype['slug'], $id)) {