本文整理汇总了PHP中sfRouting::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP sfRouting::getInstance方法的具体用法?PHP sfRouting::getInstance怎么用?PHP sfRouting::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfRouting
的用法示例。
在下文中一共展示了sfRouting::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initializeSwitch
/**
* Initialize the vars for language switch
*
* @access protected
* @param void
* @return void
*/
protected function initializeSwitch()
{
if (method_exists($this->getContext(), 'getRouting')) {
$this->routing = $this->getContext()->getRouting();
} else {
$this->routing = sfRouting::getInstance();
}
$this->request = $this->getContext()->getRequest();
$this->languages_available = array('en' => array('title' => 'English', 'image' => '/sfLanguageSwitch/images/flag/gb.png'));
}
示例2: executeLogin
public function executeLogin()
{
if ($this->getRequest()->getMethod() != sfRequest::POST) {
$r = sfRouting::getInstance();
if ($r->getCurrentRouteName() == 'login') {
$this->getRequest()->setAttribute('referer', $this->getRequest()->getReferer());
} else {
$this->getRequest()->setAttribute('referer', $r->getCurrentInternalUri());
}
} else {
$this->redirect($this->getRequestParameter('referer', '@homepage'));
}
}
示例3: execute
/**
* Executes this configuration handler.
*
* @param array An array of absolute filesystem path to a configuration file
*
* @return string Data to be written to a cache file
*
* @throws sfConfigurationException If a requested configuration file does not exist or is not readable
* @throws sfParseException If a requested configuration file is improperly formatted
*/
public function execute($configFiles)
{
// parse the yaml
$config = $this->parseYamls($configFiles);
// connect routes
$routes = sfRouting::getInstance();
foreach ($config as $name => $params) {
$routes->connect($name, $params['url'] ? $params['url'] : '/', isset($params['param']) ? $params['param'] : array(), isset($params['requirements']) ? $params['requirements'] : array());
}
// compile data
$retval = sprintf("<?php\n" . "// auto-generated by sfRoutingConfigHandler\n" . "// date: %s\n\$routes = sfRouting::getInstance();\n\$routes->setRoutes(\n%s\n);\n", date('Y/m/d H:i:s'), var_export($routes->getRoutes(), 1));
return $retval;
}
示例4: executeList
public function executeList()
{
$type = $this->getRequestParameter('type', 'all');
$c = $this->{'list' . $type}();
$c->addDescendingOrderByColumn(PostPeer::CREATED_AT);
$c->add(PostPeer::DELETED, false);
$pager = new sfPropelPager('Post', sfConfig::get('app_post_per_page', 7));
$pager->setCriteria($c);
$pager->setPage($this->getRequestParameter('page', 1));
$pager->setPeerMethod('doSelectJoinAll');
$pager->init();
$this->pager = $pager;
$r = sfRouting::getInstance();
$this->iuri = $r->getCurrentRouteName() == 'homepage' ? '@posts?page=1' : $r->getCurrentInternalUri(true);
}
示例5: execute
public function execute ($filterChain)
{
// execute next filter
$filterChain->execute();
$response = $this->getContext()->getResponse();
// execute this filter only if cache is set and no GET or POST parameters
// execute this filter not in debug mode, only if no_script_name and for 200 response code
if (
(!sfConfig::get('sf_cache') || count($_GET) || count($_POST))
||
(sfConfig::get('sf_debug') || !sfConfig::get('sf_no_script_name') || $response->getStatusCode() != 200)
)
{
return;
}
// only if cache is set for the entire page
$cacheManager = $this->getContext()->getViewCacheManager();
$uri = sfRouting::getInstance()->getCurrentInternalUri();
if ($cacheManager->isCacheable($uri) && $cacheManager->withLayout($uri))
{
// save super cache
$request = $this->getContext()->getRequest();
$pathInfo = $request->getPathInfo();
$file = sfConfig::get('sf_web_dir').'/'.$this->getParameter('cache_dir', 'cache').'/'.$request->getHost().('/' == $pathInfo[strlen($pathInfo) - 1] ? $pathInfo.'index.html' : $pathInfo);
$current_umask = umask();
umask(0000);
$dir = dirname($file);
if (!is_dir($dir))
{
mkdir($dir, 0777, true);
}
file_put_contents($file, $this->getContext()->getResponse()->getContent());
chmod($file, 0666);
umask($current_umask);
}
}
示例6: executeBeforeRendering
/**
* Executes this filter.
*
* @param sfFilterChain A sfFilterChain instance.
*/
public function executeBeforeRendering()
{
// cache only 200 HTTP status
if (200 != $this->response->getStatusCode()) {
return;
}
$uri = sfRouting::getInstance()->getCurrentInternalUri();
// save page in cache
if (isset($this->cache[$uri]) && $this->cache[$uri]['page']) {
// set some headers that deals with cache
if ($lifetime = $this->cacheManager->getClientLifeTime($uri, 'page')) {
$this->response->setHttpHeader('Last-Modified', $this->response->getDate(time()), false);
$this->response->setHttpHeader('Expires', $this->response->getDate(time() + $lifetime), false);
$this->response->addCacheControlHttpHeader('max-age', $lifetime);
}
// set Vary headers
foreach ($this->cacheManager->getVary($uri, 'page') as $vary) {
$this->response->addVaryHttpHeader($vary);
}
$this->setPageCache($uri);
} else {
if (isset($this->cache[$uri]) && $this->cache[$uri]['action']) {
// save action in cache
$this->setActionCache($uri);
}
}
// remove PHP automatic Cache-Control and Expires headers if not overwritten by application or cache
if ($this->response->hasHttpHeader('Last-Modified') || sfConfig::get('sf_etag')) {
// FIXME: these headers are set by PHP sessions (see session_cache_limiter())
$this->response->setHttpHeader('Cache-Control', null, false);
$this->response->setHttpHeader('Expires', null, false);
$this->response->setHttpHeader('Pragma', null, false);
}
// Etag support
if (sfConfig::get('sf_etag')) {
$etag = '"' . md5($this->response->getContent()) . '"';
$this->response->setHttpHeader('ETag', $etag);
if ($this->request->getHttpHeader('IF_NONE_MATCH') == $etag) {
$this->response->setStatusCode(304);
$this->response->setHeaderOnly(true);
if (sfConfig::get('sf_logging_enabled')) {
$this->getContext()->getLogger()->info('{sfFilter} ETag matches If-None-Match (send 304)');
}
}
}
// conditional GET support
// never in debug mode
if ($this->response->hasHttpHeader('Last-Modified') && !sfConfig::get('sf_debug')) {
$last_modified = $this->response->getHttpHeader('Last-Modified');
if ($this->request->getHttpHeader('IF_MODIFIED_SINCE') == $last_modified) {
$this->response->setStatusCode(304);
$this->response->setHeaderOnly(true);
if (sfConfig::get('sf_logging_enabled')) {
$this->getContext()->getLogger()->info('{sfFilter} Last-Modified matches If-Modified-Since (send 304)');
}
}
}
}
示例7: set
/**
* Saves some data in a cache file.
*
* @param string The cache id
* @param string The name of the cache namespace
* @param string The data to put in cache
*
* @return boolean true if no problem
*
* @see sfCache
*/
public function set($id, $namespace = self::DEFAULT_NAMESPACE, $data)
{
list($path, $file) = $this->getFileName($id, $namespace);
try {
$std = new Stdclass();
$std->data = $data;
$std->lastModified = time();
$internalUri = sfRouting::getInstance()->getCurrentInternalUri();
$lifeTime = $this->getLifeTime();
sfLogger::getInstance()->info("xxx: {$internalUri} - {$lifeTime}");
if (!isset(self::$mem[$this->bucket])) {
throw new Exception('This bucket was not setup correctly');
}
if (!self::$mem[$this->bucket]->set($path . $file, $std, false, $lifeTime)) {
throw new Exception('Could not save in memcache');
}
} catch (Exception $e) {
return parent::set($id, $namespace, $data);
}
}
示例8: getItemFeedLink
public function getItemFeedLink($item)
{
if ($routeName = $this->getFeedItemsRouteName()) {
$routing = sfRouting::getInstance();
$route = $routing->getRouteByName($routeName);
$url = $route[0];
$defaults = $route[4];
// we get all parameters
$params = array();
if (preg_match_all('/\\:([^\\/]+)/', $url, $matches)) {
foreach ($matches[1] as $paramName) {
$value = null;
$name = ucfirst(sfInflector::camelize($paramName));
$found = false;
foreach (array('getFeed' . $name, 'get' . $name) as $methodName) {
if (method_exists($item, $methodName)) {
$value = $item->{$methodName}();
$found = true;
break;
}
}
if (!$found) {
if (array_key_exists($paramName, $defaults)) {
$value = $defaults[$paramName];
} else {
$error = 'Cannot find a "getFeed%s()" or "get%s()" method for object "%s" to generate URL with the "%s" route';
$error = sprintf($error, $name, $name, get_class($item), $routeName);
throw new sfException($error);
}
}
$params[] = $paramName . '=' . $value;
}
}
return $this->context->getController()->genUrl($routeName . ($params ? '?' . implode('&', $params) : ''), true);
}
foreach (array('getFeedLink', 'getLink', 'getUrl') as $methodName) {
if (method_exists($item, $methodName)) {
return $this->context->getController()->genUrl($item->{$methodName}(), true);
}
}
if ($this->getLink()) {
return sfContext::getInstance()->getController()->genUrl($this->getLink(), true);
} else {
return $this->context->getController()->genUrl('/', true);
}
}
示例9: getCurrentCacheUri
public static function getCurrentCacheUri()
{
// for home, portals filter and default list, we adapt cache uri so that we can cache
// cases where all cultures are displayed, or only the one from the interface (see #723)
$context = sfContext::getInstance();
$module = $context->getModuleName();
$action = $context->getActionName();
$request_parameters = $context->getRequest()->getParameterHolder()->getAll();
unset($request_parameters['module']);
unset($request_parameters['action']);
$is_cacheable_filter_list = false;
if (in_array($action, array('filter', 'list'))) {
$count_request_parameters = count($request_parameters);
switch ($action) {
case 'list':
if (!isset($request_parameters['page'])) {
$request_parameters['page'] = 1;
$count_request_parameters++;
}
if ($request_parameters['page'] <= 2 && ($count_request_parameters == 1 || $module == 'outings' && $count_request_parameters == 3 && isset($request_parameters['orderby']) && $request_parameters['orderby'] == 'date' && isset($request_parameters['order']) && $request_parameters['order'] == 'desc')) {
$is_cacheable_filter_list = true;
}
break;
case 'filter':
if (!count($request_parameters)) {
$is_cacheable_filter_list = true;
}
break;
default:
break;
}
}
$uri = sfRouting::getInstance()->getCurrentInternalUri();
$il = 'il=' . $context->getUser()->getCulture();
$pl = '';
$pa = '';
$credential = (int) $context->getUser()->isConnected() + (int) $context->getUser()->hasCredential('moderator');
$c = '&c=' . $credential;
if ($action == 'home' || $module == 'portals' && $action == 'view' || $is_cacheable_filter_list) {
if ($action == 'home' || $module == 'portals' && $action == 'view') {
$module_cache = 'outings';
} else {
$module_cache = $module;
}
$perso = c2cPersonalization::getInstance();
list($langs_enable, $areas_enable, $activities_enable) = c2cPersonalization::getDefaultFilters($module_cache);
$is_main_filter_switch_on = $perso->isMainFilterSwitchOn();
$activities_filter = $perso->getActivitiesFilter();
if ($is_main_filter_switch_on) {
if ($action != 'filter' && ($action != 'list' || $langs_enable) && $perso->areDefaultLanguagesFilters()) {
$pl = '&pl=1';
}
if ($activities_enable && count($activities_filter)) {
$pa = '&pa=' . implode('-', $activities_filter);
}
}
switch ($action) {
case 'view':
if (!in_array($module, array('outings', 'images', 'articles', 'users')) && isset($request_parameters['version'])) {
$c = '';
}
break;
case 'history':
if (!in_array($module, array('outings', 'images', 'articles', 'users'))) {
$c = '';
}
case 'whatsnew':
$c = '';
break;
case 'list':
if (strpos($uri, 'page=') === false) {
$uri .= (strpos($uri, '?') ? '&' : '?') . 'page=1';
}
if ($module == 'users') {
$c = '&c=' . min($credential, 1);
} else {
$c = '';
}
break;
default:
break;
}
}
$uri .= (strstr($uri, '?') ? '&' : '?') . $il . $pl . $pa . $c;
return $uri;
}
示例10: array
<?php
// Adding polls routes if option has not been disabled in app.yml
// @see http://www.symfony-project.com/book/trunk/09-Links-and-the-Routing-System#Creating%20Rules%20Without%20routing.yml
if (sfConfig::get('app_sfPropelPollsPlugin_routes_register', true) && in_array('sfPolls', sfConfig::get('sf_enabled_modules'))) {
$r = sfRouting::getInstance();
# Polls list route
$r->prependRoute('sf_propel_polls_list', '/polls', array('module' => 'sfPolls', 'action' => 'list'), array('id' => '\\d+'));
# Poll detail (form) route
$r->prependRoute('sf_propel_polls_detail', '/poll_detail/:id', array('module' => 'sfPolls', 'action' => 'detail'), array('id' => '\\d+'));
# Poll results route
$r->prependRoute('sf_propel_polls_results', '/poll_results/:id', array('module' => 'sfPolls', 'action' => 'results'), array('id' => '\\d+'));
# Poll vote route
$r->prependRoute('sf_propel_polls_vote', '/poll_vote', array('module' => 'sfPolls', 'action' => 'vote'), array('id' => '\\d+'));
}
示例11: getItemFeedLink
public function getItemFeedLink($item)
{
if ($routeName = $this->getFeedItemsRouteName()) {
$routing = sfRouting::getInstance();
$route = $routing->getRouteByName($routeName);
$url = $route[0];
// we get all parameters
$params = array();
if (preg_match_all('/\\:([^\\/]+)/', $url, $matches)) {
foreach ($matches[1] as $paramName) {
$value = null;
$name = ucfirst(sfInflector::camelize($paramName));
foreach (array('getFeed' . $name, 'get' . $name) as $methodName) {
if (method_exists($item, $methodName)) {
$value = $item->{$methodName}();
}
}
if ($value === null) {
$error = 'Cannot find a matching method name for "%s" parameter to generate URL for the "%s" route name';
$error = sprintf($error, $name, $routeName);
throw new sfException($error);
}
$params[] = $paramName . '=' . $value;
}
}
return $this->context->getController()->genUrl($routeName . ($params ? '?' . implode('&', $params) : ''), true);
}
foreach (array('getFeedLink', 'getLink', 'getUrl') as $methodName) {
if (method_exists($item, $methodName)) {
return $this->context->getController()->genUrl($item->{$methodName}(), true);
}
}
if ($this->getLink()) {
return sfContext::getInstance()->getController()->genUrl($this->getLink(), true);
} else {
return $this->context->getController()->genUrl('/', true);
}
}
示例12: include_partial
<?php
include_partial('tabs', array('ramo' => $sf_params->get('ramo'), 'gruppi' => false));
if (sfRouting::getInstance()->getCurrentRouteName() == 'giorni_di_carica') {
slot('force_canonical');
if ($sf_params->get('ramo') == 'senato') {
echo "\n<link rel=\"canonical\" href=\"" . url_for('@giorni_di_carica_senatori', true) . "\" />";
} else {
echo "\n<link rel=\"canonical\" href=\"" . url_for('@giorni_di_carica_deputati', true) . "\" />";
}
end_slot();
}
?>
<div class="row">
<div class="twelvecol">
<?php
echo include_partial('secondLevelMenuParlamentari', array('current' => 'giorni_di_carica', 'ramo' => $sf_params->get('ramo')));
?>
<div class="intro-box"><p style="font-size:14px;">
Non manca in Italia occasione in cui non si discuta, a torto o a ragione, della necessità del ricambio della classe politica.<br/>
Per quanto riguarda i <?php
echo $ramo == 'C' ? 'deputati' : 'senatori (esclusi quelli a a vita)';
?>
attualmente in carica abbiamo calcolato da quanto tempo ricoprono incarichi parlamentari, ovvero per quanti anni e giorni sono stati seduti sugli scranni di Montecitorio o Palazzo Madama. Il calcolo viene aggiornato quotidianamente.<br/>
Oltre al riepilogo complessivo ed a quello diviso per gruppi parlamentari, di seguito la lista dei primi cinquanta <?php
echo $ramo == 'C' ? 'deputati' : 'senatori (esclusi quelli a a vita)';
?>
"più esperti" (<?php
echo link_to('clicca qui', '@giorni_di_carica_' . ($ramo == 'C' ? 'senatori' : 'deputati')) . ' se vuoi la lista dei ' . ($ramo == 'C' ? 'senatori' : 'deputati');
示例13: getItemFeedLink
private static function getItemFeedLink($item, $routeName = '', $fallback_url = '')
{
if ($routeName) {
if (method_exists('sfRouting', 'getInstance')) {
$route = sfRouting::getInstance()->getRouteByName($routeName);
$url = $route[0];
$paramNames = $route[2];
$defaults = $route[4];
} else {
$routes = sfContext::getInstance()->getRouting()->getRoutes();
$route = $routes[substr($routeName, 1)];
if ($route instanceof sfRoute) {
$url = $route->getPattern();
$paramNames = array_keys($route->getVariables());
$defaults = $route->getDefaults();
} else {
$url = $route[0];
$paramNames = array_keys($route[2]);
$defaults = $route[3];
}
}
// we get all parameters
$params = array();
foreach ($paramNames as $paramName) {
$value = null;
$name = ucfirst(sfInflector::camelize($paramName));
$found = false;
foreach (array('getFeed' . $name, 'get' . $name) as $methodName) {
if (method_exists($item, $methodName)) {
$value = $item->{$methodName}();
$found = true;
break;
}
}
if (!$found) {
if (array_key_exists($paramName, $defaults)) {
$value = $defaults[$paramName];
} else {
$error = 'Cannot find a "getFeed%s()" or "get%s()" method for object "%s" to generate URL with the "%s" route';
$error = sprintf($error, $name, $name, get_class($item), $routeName);
throw new sfException($error);
}
}
$params[] = $paramName . '=' . $value;
}
return sfContext::getInstance()->getController()->genUrl($routeName . ($params ? '?' . implode('&', $params) : ''), true);
}
foreach (array('getFeedLink', 'getLink', 'getUrl') as $methodName) {
if (method_exists($item, $methodName)) {
return sfContext::getInstance()->getController()->genUrl($item->{$methodName}(), true);
}
}
if ($fallback_url) {
return sfContext::getInstance()->getController()->genUrl($fallback_url, true);
} else {
return sfContext::getInstance()->getController()->genUrl('/', true);
}
}
示例14: isUriCached
/**
* Tests if the given uri is cached.
*
* @param string Uniform resource identifier
* @param boolean Flag for checking the cache
* @param boolean If have or not layout
*
* @param sfTestBrowser Test browser instance
*/
public function isUriCached($uri, $boolean, $with_layout = false)
{
$cacheManager = $this->getContext()->getViewCacheManager();
// check that cache is enabled
if (!$cacheManager) {
$this->test->ok(!$boolean, 'cache is disabled');
return $this;
}
if ($uri == sfRouting::getInstance()->getCurrentInternalUri()) {
$main = true;
$type = $with_layout ? 'page' : 'action';
} else {
$main = false;
$type = $uri;
}
// check layout configuration
if ($cacheManager->withLayout($uri) && !$with_layout) {
$this->test->fail('cache without layout');
$this->test->skip('cache is not configured properly', 2);
} else {
if (!$cacheManager->withLayout($uri) && $with_layout) {
$this->test->fail('cache with layout');
$this->test->skip('cache is not configured properly', 2);
} else {
$this->test->pass('cache is configured properly');
// check page is cached
$ret = $this->test->is($cacheManager->has($uri), $boolean, sprintf('"%s" %s in cache', $type, $boolean ? 'is' : 'is not'));
// check that the content is ok in cache
if ($boolean) {
if (!$ret) {
$this->test->fail('content in cache is ok');
} else {
if ($with_layout) {
$response = unserialize($cacheManager->get($uri));
$content = $response->getContent();
$this->test->ok($content == $this->getResponse()->getContent(), 'content in cache is ok');
} else {
if (true === $main) {
$ret = unserialize($cacheManager->get($uri));
$content = $ret['content'];
$this->test->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok');
} else {
$content = $cacheManager->get($uri);
$this->test->ok(false !== strpos($this->getResponse()->getContent(), $content), 'content in cache is ok');
}
}
}
}
}
}
return $this;
}
示例15: slot
<?php
if (sfRouting::getInstance()->getCurrentRouteName() == 'default_symfony') {
slot('force_canonical');
echo "\n<link rel=\"canonical\" href=\"" . url_for('@classifiche_parlamento', true) . "\" />";
end_slot();
}
?>
<div class="row" id="tabs-container">
<ul id="content-tabs" class="float-container tools-container">
<li class="current">
<h2>
<?php
echo "Le classifiche";
?>
</h2>
</li>
</ul>
</div>
<div class="row">
<div class="twelvecol">
<div style="padding:5px; width:73%;">
<p class="tools-container"><a class="ico-help" href="#">come sono calcolate le classifiche</a></p>
<div style="display: none;" class="help-box float-container">
<div class="inner float-container">
<a class="ico-close" href="#">chiudi</a><h5>come sono calcolate le classifiche ?</h5>
<p>I dati sulle <strong>presenze</strong> e <strong>assenze</strong> si riferiscono alle votazioni elettroniche che si svolgono nell'Assemblea di Camera e Senato dall'inizio della legislatura. I dati dunque si riferiscono solo al totale delle presenze e assenze nelle votazioni elettroniche in Aula. Con assenza si intendono i casi di non partecipazione al voto: sia quello in cui il parlamentare è fisicamente assente (e non in missione) sia quello in cui è presente ma non vota. Purtroppo attualmente i sistemi di documentazione dei resoconti di Camera e Senato non consentono di distinguere un caso dall'altro. I regolamenti non prevedono la registrazione del motivo dell'assenza al voto del parlamentare. Non si può distinguere, pertanto, l'assenza ingiustificata da quella, ad esempio, per ragioni di salute. <br />