当前位置: 首页>>代码示例>>PHP>>正文


PHP Slim::urlFor方法代码示例

本文整理汇总了PHP中Slim\Slim::urlFor方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::urlFor方法的具体用法?PHP Slim::urlFor怎么用?PHP Slim::urlFor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Slim\Slim的用法示例。


在下文中一共展示了Slim::urlFor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize

/**
 * A group of Twig functions for use in view templates
 *
 * @param  Twig_Environment $env
 * @param  Slim             $app
 * @return void
 */
function initialize(Twig_Environment $env, Slim $app)
{
    $env->addExtension(new TwigExtension());
    $env->addFunction(new Twig_SimpleFunction('urlFor', function ($routeName, $params = array()) use($app) {
        $url = $app->urlFor($routeName, $params);
        return $url;
    }));
    $env->addFunction(new Twig_SimpleFunction('hash', function ($value) {
        return md5($value);
    }));
    $env->addFunction(new Twig_SimpleFunction('gravatar', function ($email_hash, $size = 40) {
        $size = (int) $size == 0 ? 20 : (int) $size;
        $url = 'https://secure.gravatar.com/avatar/' . $email_hash . '?d=mm&s=' . $size;
        if (empty($email_hash)) {
            $url .= '&f=y';
        }
        return $url;
    }));
    $env->addFunction(new Twig_SimpleFunction('getCurrentUrl', function () {
        return $_SERVER['REQUEST_URI'];
    }));
    $env->addFunction(new Twig_SimpleFunction('urlForTalk', function ($eventSlug, $talkSlug, $params = array()) use($app) {
        return $app->urlFor('talk', array('eventSlug' => $eventSlug, 'talkSlug' => $talkSlug));
    }));
    $env->addFunction(new Twig_SimpleFunction('shortUrlForTalk', function ($talkStub) use($app) {
        $scheme = $app->request()->getScheme();
        $host = $app->request()->headers('host');
        return "{$scheme}://{$host}" . $app->urlFor('talk-quicklink', array('talkStub' => $talkStub));
    }));
    $env->addFunction(new Twig_SimpleFunction('shortUrlForEvent', function ($eventStub) use($app) {
        $scheme = $app->request()->getScheme();
        $host = $app->request()->headers('host');
        return "{$scheme}://{$host}" . $app->urlFor('event-quicklink', array('stub' => $eventStub));
    }));
    $env->addFunction(new Twig_SimpleFunction('dateRange', function ($start, $end, $format = 'd.m.Y', $separator = ' - ') use($app) {
        $formatter = new \Org_Heigl\DateRange\DateRangeFormatter();
        $formatter->setFormat($format);
        $formatter->setSeparator($separator);
        if (!$start instanceof \DateTimeInterface) {
            $start = new \DateTime($start);
        }
        if (!$end instanceof \DateTimeInterface) {
            $end = new \DateTime($end);
        }
        return $formatter->getDateRange($start, $end);
    }));
    /**
     * wrapped Slim request function getPath()
     */
    $env->addFunction(new Twig_SimpleFunction('currentPath', function () use($app) {
        $request = $app->request;
        $params = $app->request->get();
        $queryString = http_build_query($params);
        if ($queryString) {
            return $request->getPath() . urlencode('?' . $queryString);
        } else {
            return $request->getPath();
        }
    }));
}
开发者ID:e3betht,项目名称:joindin-web2,代码行数:67,代码来源:Functions.php

示例2: cleanupOldFiles

 public function cleanupOldFiles()
 {
     $_SESSION['DB_DONE'] = true;
     $cleanupList = array_merge($this->pluginFinder->getDummyPlugins(), $this->filesFinder->getCleanupFiles());
     $this->cleanupMedia();
     if (count($cleanupList) == 0) {
         $_SESSION['CLEANUP_DONE'] = true;
         $this->response->redirect($this->app->urlFor('done'));
     }
     if ($this->request->isPost()) {
         $result = [];
         foreach ($cleanupList as $path) {
             $result = array_merge($result, Utils::cleanPath($path));
         }
         if (count($result) == 0) {
             $_SESSION['CLEANUP_DONE'] = true;
             $this->response->redirect($this->app->urlFor('done'));
         } else {
             $result = array_map(function ($path) {
                 return substr($path, strlen(SW_PATH) + 1);
             }, $result);
             $this->app->render('cleanup.php', ['cleanupList' => $result, 'error' => true]);
         }
     } else {
         $cleanupList = array_map(function ($path) {
             return substr($path, strlen(SW_PATH) + 1);
         }, $cleanupList);
         $this->app->render('cleanup.php', ['cleanupList' => $cleanupList, 'error' => false]);
     }
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:30,代码来源:CleanupController.php

示例3: subscribeAction

 /**
  * Handle the subscription form request
  */
 public function subscribeAction()
 {
     try {
         $this->subscribeForm->validate($this->app->request()->params());
     } catch (FormValidationException $e) {
         $this->session->flash('message', 'Oh no, you have entered invalid data. Please correct your input and try again.');
         $this->session->flash('errors', $e->getErrors());
         $this->session->flash('input', $this->app->request()->params());
         $this->app->response->redirect($this->app->urlFor('home'));
         return;
     }
     //
     // TODO: Subscribe the client to your newsletter list... or stuff
     //
     $this->session->flash('message', 'Thanks for your request. You have successfully subscribed for our newsletter.');
     $this->app->response->redirect($this->app->urlFor('home'));
 }
开发者ID:seanc,项目名称:slim-boilerplate-1,代码行数:20,代码来源:HomeController.php

示例4: url

 /**
  * $crud->url("user", ["male", "1970"]);
  * @param $routeName
  * @param array $data
  * @return string
  */
 public function url($routeName, $data = [])
 {
     $data2 = [];
     $i = 1;
     // Map key (p1, p2, p3....)
     foreach ($data as $value) {
         $data2["p" . $i++] = $value;
     }
     return $this->slim->urlFor("_louisCRUD_" . $routeName, $data2);
 }
开发者ID:louislam,项目名称:louislam-crud,代码行数:16,代码来源:SlimLouisCRUD.php

示例5: checkRequirements

 public function checkRequirements()
 {
     $paths = Utils::getPaths(SW_PATH . "/engine/Shopware/Components/Check/Data/Path.xml");
     clearstatcache();
     $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH);
     foreach ($systemCheckPathResults as $value) {
         if (!$value['result']) {
             $fileName = SW_PATH . '/' . $value['name'];
             @mkdir($fileName, 0777, true);
             @chmod($fileName, 0777);
         }
     }
     clearstatcache();
     $systemCheckPathResults = Utils::checkPaths($paths, SW_PATH);
     $hasErrors = false;
     foreach ($systemCheckPathResults as $value) {
         if (!$value['result']) {
             $hasErrors = true;
         }
     }
     $directoriesToDelete = ['engine/Library/Mpdf/tmp' => false, 'engine/Library/Mpdf/ttfontdata' => false];
     CommonUtils::clearOpcodeCache();
     $results = [];
     foreach ($directoriesToDelete as $directory => $deleteDirecory) {
         $result = true;
         $filePath = SW_PATH . '/' . $directory;
         Utils::deleteDir($filePath, $deleteDirecory);
         if ($deleteDirecory && is_dir($filePath)) {
             $result = false;
             $hasErrors = true;
         }
         if ($deleteDirecory) {
             $results[$directory] = $result;
         }
     }
     if (!$hasErrors && $this->app->request()->get("force") !== "1") {
         // No errors, skip page except if force parameter is set
         $this->app->redirect($this->app->urlFor("dbmigration"));
     }
     $isSkippableCheck = $this->app->config('skippable.check');
     if ($isSkippableCheck && $this->app->request()->get("force") !== "1") {
         // No errors, skip page except if force parameter is set
         $this->app->redirect($this->app->urlFor("dbmigration"));
     }
     $this->app->render('checks.php', ['systemCheckResultsWritePermissions' => $systemCheckPathResults, 'filesToDelete' => $results, 'error' => $hasErrors]);
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:46,代码来源:RequirementsController.php

示例6: foreach

    $echolinksys->dataFromTheServer();
    $app->log->info("Echolink CRON System - Update was performed from a remote server echolink.org");
    if ($echolinksys->responseStat != System::RESPONSE_OK) {
        $app->log->info("Echolink CRON System - Server problem ! (CODE: " . $echolinksys->responseStat . ")");
        $echolinksys->addHistoryLog("Server response problem! (CODE: " . $echolinksys->responseStat . ")");
    } else {
        $body = "Byl změněn stav převaděče.\r\n" . "Call: ";
        foreach ($echolinksys->messageEmail as $email) {
            //set template for email!
            $body = "Byl změněn stav převaděče.\r\n" . "Call: " . $email["callname"] . "\r\n" . "Nyní stav: " . ($email["newStatus"] == 1 ? "true" : "false") . "\r\n" . "Datum poslední změny: " . $email["oldCheckDate"] . "\r\n" . "Datum nynější změny: " . $email["checkDate"] . "\r\n";
            $echolinksys->mail($email["email"], "Echolink", $body, $from_name = "EcholinkSyS");
            $echolinksys->addHistoryLog("E-mail send to " . $email["callname"]);
            $app->log->info("Echolink CRON System - Email send to " . $email["callname"]);
        }
    }
    $url = $app->urlFor('list', array());
    $app->redirect($url);
})->name('check');
// updating data
$app->get('/cron', function () use($app) {
    $app->log->info("Echolink CRON System - '/cron' route");
    $echolinksys = new System("mysql:host=" . host . ";dbname=" . database, username, password);
    $echolinksys->dataFromTheServer();
    $app->log->info("Echolink CRON System - CRON -> Update was performed from a remote server echolink.org");
    if ($echolinksys->responseStat != System::RESPONSE_OK) {
        $app->log->info("Echolink CRON System - Server problem ! (CODE: " . $echolinksys->responseStat . ")");
        $echolinksys->addHistoryLog("Server response problem! (CODE: " . $echolinksys->responseStat . ")");
    } else {
        $body = "Byl změněn stav převaděče.\r\n" . "Call: ";
        foreach ($echolinksys->messageEmail as $email) {
            //set template for email!
开发者ID:ok2uec,项目名称:echolink-cron-system,代码行数:31,代码来源:index.php

示例7: getCurrentUrl

 /**
  * @param  array  $params
  * @return string
  */
 public function getCurrentUrl($params = [])
 {
     $entries = $this->entries;
     $currentEntry = \current($entries);
     return $this->slim->urlFor($currentEntry, $params);
 }
开发者ID:GerDner,项目名称:luck-docker,代码行数:10,代码来源:MenuHelper.php

示例8: array

        $app->response->finalize();
    }
    $app->logger->alert('UNHANDLED EXCEPTION', array('exception' => $e));
    if (isset($_SESSION['username']) && !empty($_SESSION['username'])) {
        return $app->render('errors/500-authed.mustache');
    }
    $app->render('errors/500-guest.mustache');
});
$app->view(new Mustache());
$app->view->parserOptions = $config['mustache'];
$app->view->appendData(array('copyrightYear' => date('Y')));
$app->add(new Navigation());
$app->add(new SessionCookie(array('expires' => '12 hours')));
$isLoggedIn = function () use($app) {
    if (empty($_SESSION['username'])) {
        $app->redirect($app->urlFor('home'));
    }
};
// home
$app->get('/', function () use($app) {
    $isAuthenticated = empty($_SESSION['username']) ? false : true;
    $app->render('home/index.mustache', array('isAuthenticated' => $isAuthenticated));
})->name('home');
$app->get('/login', function () use($app) {
    $app->redirect($app->urlFor('home'));
});
// login
$app->post('/login', function () use($app) {
    $params = $app->request()->post();
    // make sure the user name was passed.
    $username = trim($params['username']);
开发者ID:graphstory,项目名称:graph-kit-php,代码行数:31,代码来源:app.php

示例9: configureRoutes

 /**
  * Configure routes to be handled by application.
  *
  * @param \Slim\Slim $slim Application
  */
 protected function configureRoutes(\Slim\Slim $slim)
 {
     $middleware = array('must-revalidate' => function () use($slim) {
         $slim->response->headers->set('Cache-Control', 'private, must-revalidate, max-age=0');
         $slim->response->headers->set('Expires', 'Thu, 01 Jan 1970 00:00:00 GMT');
     }, 'inject-user' => function () use($slim) {
         $user = $slim->authManager->getUserData();
         $slim->view->set('user', $user);
     }, 'require-user' => function () use($slim) {
         if ($slim->authManager->isAnonymous()) {
             if ($slim->request->isGet()) {
                 $uri = $slim->request->getUrl() . $slim->request->getPath();
                 $qs = Form::qsMerge();
                 if ($qs) {
                     $uri = "{$uri}?{$qs}";
                 }
                 $_SESSION[AuthManager::NEXTPAGE_SESSION_KEY] = $uri;
             }
             // FIXME: use i18n
             $slim->flash('error', 'Login required');
             $slim->flashKeep();
             $slim->redirect($slim->urlFor('login'));
         }
     });
     $slim->group('/', $middleware['inject-user'], function () use($slim, $middleware) {
         App::redirect($slim, '', 'random', 'home');
         App::redirect($slim, 'index', 'random');
         $slim->get('random', function () use($slim) {
             $page = new Pages\Random($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page();
         })->name('random');
         $slim->get('random.json', function () use($slim) {
             $slim->response->headers->set('Content-Type', 'application/json');
             $page = new Pages\Random($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page->setTemplate('random.json');
             $page();
         })->name('random.json');
         $slim->get('search', function () use($slim) {
             $page = new Pages\Search($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page();
         })->name('search');
         $slim->get('top', function () use($slim) {
             $page = new Pages\Top($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page();
         })->name('top');
         App::template($slim, 'login');
         $slim->get('logout', $middleware['must-revalidate'], function () use($slim) {
             $slim->authManager->logout();
             $slim->redirect($slim->urlFor('home'));
         })->name('logout');
         App::template($slim, 'about');
         App::template($slim, 'help');
     });
     // end group '/'
     $slim->group('/quip/', $middleware['inject-user'], function () use($slim, $middleware) {
         $slim->get(':id', function ($id) use($slim) {
             $page = new Pages\Quip($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page($id);
         })->name('quip');
         $slim->get(':id/edit', $middleware['require-user'], function ($id) use($slim) {
             $page = new Pages\Edit($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page($id);
         })->name('edit');
         $slim->post(':id/post', $middleware['require-user'], function ($id) use($slim) {
             $page = new Pages\Edit($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page($id);
         })->name('edit_post');
         $slim->post(':id/delete', $middleware['require-user'], function ($id) use($slim) {
             $page = new Pages\Delete($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page($id);
         })->name('delete_post');
         $slim->post(':id/vote', $middleware['require-user'], function ($id) use($slim) {
             $page = new Pages\Vote($slim);
             $page->setI18nContext($slim->i18nContext);
             $page->setQuips($slim->quips);
             $page($id);
         })->name('vote_post');
     });
     $slim->group('/oauth/', function () use($slim) {
//.........这里部分代码省略.........
开发者ID:bd808,项目名称:quips,代码行数:101,代码来源:App.php

示例10: urlWithApikeyFor

 public function urlWithApikeyFor($name, $params = [])
 {
     return $this->app->urlFor($name, $params) . '?apikey=' . $GLOBALS['config']['apikey'];
 }
开发者ID:hgabor,项目名称:website2feed,代码行数:4,代码来源:SimpleView.php

示例11: stdClass

                    $routeItem->route = '';
                    if ($pages[$routeName][$lang]['route'] == '/') {
                        $routeItem->route = '/';
                    }
                }
                if ($pages[$routeName][$lang]['route'] != '/') {
                    $routeItem->route .= $pages[$routeName][$lang]['route'];
                }
            }
            $menu_langs[] = $routeItem;
            $routeItem = null;
        }
    }
    $data['menu_langs'] = $menu_langs;
    $app->view->appendData($data);
});
$data['menu'] = [];
foreach ($data['langs']['menu'] as $key => $value) {
    $menuItem = new stdClass();
    $menuItem->lang = $value;
    $menuItem->route = $app->urlFor($key);
    if (strlen($menuItem->route) > 1) {
        if (substr($menuItem->route, -1) == '/') {
            $menuItem->route = substr($menuItem->route, 0, -1);
        }
    }
    $data['menu'][] = $menuItem;
    $menuItem = null;
}
$app->view->appendData($data);
$app->run();
开发者ID:sond3,项目名称:sliminit,代码行数:31,代码来源:core.php

示例12: Slim

<?php

use SecucardConnect\Util\Logger;
use Slim\Slim;
use Slim\Views\Twig;
use Slim\Views\TwigExtension;
include_once __DIR__ . "/init.php";
/*
 * Prepare demo app
 */
$app = new Slim(array('debug' => true, 'templates.path' => __DIR__));
$app->container->singleton('log', function () {
    return new Logger(fopen("php://stdout", "a"), true);
});
// Prepare twig-view-renderer
$app->view(new Twig());
$app->view->parserOptions = array('charset' => 'utf-8', 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true, 'debug' => true);
$app->view->parserExtensions = array(new TwigExtension());
// add extensions
$app->view->getInstance()->addExtension(new Twig_Extension_Debug());
// add methods
$function = new Twig_SimpleFunction('urlFor', function ($name) use($app) {
    $url = $app->urlFor($name);
    // add index.php to url, so it is not broken
    if (strpos($url, 'index.php') === false) {
        $url = str_replace($name, 'index.php/' . $name, $url);
    }
    return $url;
});
$app->view->getInstance()->addFunction($function);
开发者ID:secucard,项目名称:secucard-connect-php-sdk-demo,代码行数:30,代码来源:init-slim.php

示例13: strtoupper

 // setup variables from the incoming post
 $album = $app->request->post('album');
 $email = $app->request->post('email');
 $code = strtoupper($app->request->post('code'));
 $subscribe = $app->request->post('mailing_list');
 $address = $app->request->post('address');
 // Set current entries to cookies
 $app->setCookie('code', $code);
 $app->setCookie('email', $email);
 $app->setCookie('album', $album);
 $app->setCookie('subscribe', $subscribe);
 // Make sure the Honey Pot field is empty.
 if (!empty($address)) {
     $app->flash('error', 'Your form submission has an error.');
     // Push them back to the main screen with generic error message
     $app->redirect($app->urlFor('home'));
 } elseif (!empty($code) && !empty($email)) {
     // Clean up the form submissions
     $cleanCode = filter_var($code, FILTER_SANITIZE_STRING);
     $cleanEmail = filter_var($email, FILTER_SANITIZE_EMAIL);
     $cleanAlbum = filter_var($album, FILTER_SANITIZE_STRING);
     // validate the email format
     $validEmail = filter_var($cleanEmail, FILTER_VALIDATE_EMAIL);
     // Validate the code entered
     $validCode = $dl->validate_code($album, $code);
     // Check if the code and email entered are valid
     if ($validEmail && $validCode === 200) {
         // Subscribe the user if they kept the subscribe option checked
         if ($subscribe) {
             $addUser = $mail->newsletterSignup($cleanEmail);
             print_r($addUser);
开发者ID:nblakefriend,项目名称:download,代码行数:31,代码来源:index.php

示例14: urlFor

 public function urlFor($path)
 {
     return $this->app->urlFor('assets', array('path' => trim($path, '/')));
 }
开发者ID:lalop,项目名称:aphet,代码行数:4,代码来源:Slim.php

示例15: function

        echo "Couldn't find the Message in the body.";
        $app->response()->setStatus(400);
    }
})->name("webhook");
/**
 * Install webhook with Telegram API. Uses the current url and "webhook" route.
 * POST to this URL to install your webhook with Telegram.
 *
 * Note: Telegram requires your webhooks to use HTTPS.
 *
 * For example:
 *
 * POST https://bot.mydomain.com/install HTTP/1.1
 */
$app->post("/install", function () use($app) {
    $url = $app->request()->getUrl() . $app->urlFor("webhook");
    try {
        $app->telegram->setWebhook($url);
    } catch (\Exception $e) {
        echo "Couldn't set the webhook. Have you set the bot auth token correctly?";
        $app->response()->setStatus(403);
    }
});
/**
 * Uninstall the webhook by sending a blank URL. Post to this URL to uninstall
 * your webhook.
 *
 * For example:
 *
 * POST https://bot.mydomain.com/uninstall HTTP/1.1
 */
开发者ID:nellurichaitanya,项目名称:telegram-skeleton,代码行数:31,代码来源:index.php


注:本文中的Slim\Slim::urlFor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。