當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Dispatcher::getParam方法代碼示例

本文整理匯總了PHP中Phalcon\Mvc\Dispatcher::getParam方法的典型用法代碼示例。如果您正苦於以下問題:PHP Dispatcher::getParam方法的具體用法?PHP Dispatcher::getParam怎麽用?PHP Dispatcher::getParam使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phalcon\Mvc\Dispatcher的用法示例。


在下文中一共展示了Dispatcher::getParam方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: beforeExecuteRoute

 public function beforeExecuteRoute(\Phalcon\Events\Event $event, \Phalcon\Mvc\Dispatcher $dispatcher)
 {
     /** @var \Phalcon\Http\Request $request */
     $request = $dispatcher->getDI()->getService('request')->resolve();
     if ($dispatcher->getParam('lang')) {
         $lang = $dispatcher->getParam('lang');
     } else {
         $lang = $request->getBestLanguage();
     }
     $view = $dispatcher->getDI()->getService('view')->resolve();
     $translationHelper = $dispatcher->getDI()->get(\Sb\Phalcon\Helpers\TranslationHelper::SERVICE_NAME);
     $translationHelper->setLang($lang);
     $view->setVar('t', $translationHelper->getTranslation());
 }
開發者ID:sb15,項目名稱:phalcon-ext,代碼行數:14,代碼來源:TranslationPlugin.php

示例2: __construct

 public function __construct(Dispatcher $dispatcher)
 {
     $request = $this->getDI()->get('request');
     $queryLang = $request->getQuery('lang');
     if (!$queryLang) {
         $lang = $dispatcher->getParam('lang');
     } else {
         $lang = $queryLang;
     }
     switch ($lang) {
         case 'uk':
             define('LANG', 'uk');
             define('LANG_SUFFIX', '_uk');
             define('LANG_URL', '/uk');
             define('LOCALE', 'uk_UA');
             break;
         case 'en':
             define('LANG', 'en');
             define('LANG_SUFFIX', '_en');
             define('LANG_URL', '/en');
             define('LOCALE', 'en_EN');
             break;
         default:
             define('LANG', 'ru');
             define('LANG_SUFFIX', '');
             define('LANG_URL', '/');
             define('LOCALE', 'ru_RU');
     }
     Locale::setDefault(LOCALE);
     $this->getDI()->set('translate', new \Application\Localization\GettextAdapter(array('locale' => LOCALE, 'lang' => LANG, 'file' => 'messages', 'directory' => APPLICATION_PATH . '/lang')));
 }
開發者ID:bitclaw,項目名稱:phalcon-skeleton,代碼行數:31,代碼來源:LocalizationPlugin.php

示例3: __construct

 public function __construct(Dispatcher $dispatcher)
 {
     $cmsCache = new CmsCache();
     $languages = $cmsCache->get('languages');
     $defaultLangArray = array_values(array_slice($languages, 0, 1));
     $defaultLang = $defaultLangArray[0];
     $request = $this->getDI()->get('request');
     $queryLang = $request->getQuery('lang');
     if (!$queryLang) {
         $langParam = $dispatcher->getParam('lang');
     } else {
         $langParam = $queryLang;
     }
     if (!$langParam) {
         $langParam = $defaultLang['iso'];
     }
     foreach ($languages as $language) {
         if ($langParam == $language['iso']) {
             define('LANG', $language['iso']);
             define('LANG_URL', '/' . $language['url']);
         }
     }
     if (!defined('LANG')) {
         define('LANG', $defaultLang['iso']);
         \Application\Mvc\Model\Model::$lang = $defaultLang['iso'];
     }
     if (!defined('LANG_URL')) {
         define('LANG_URL', $defaultLang['url']);
     }
     $translations = \Cms\Model\Translate::findCachedByLangInArray(LANG);
     $this->getDI()->set('translate', new \Phalcon\Translate\Adapter\NativeArray(['content' => $translations]));
 }
開發者ID:devsnippet,項目名稱:yona-cms,代碼行數:32,代碼來源:Localization.php

示例4: beforeDispatch

 /**
  * puts any params in the url into an assoc array in the dispatcher
  * for example given this url
  *		/en/employer/profile/edit/id/5/company/6/email/test@test.com
  * then in the controller
  *		$this->dispatcher->getParam('id') = 5
  *		$this->dispatcher->getParam('company') = 6
  *		$this->dispatcher->getParam('email') = test@test.com
  * @param Event $event
  * @param Dispatcher $dispatcher
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $key_params = array();
     $params = $dispatcher->getParams();
     foreach ($params as $number => $value) {
         if ($number & 1) {
             $key_params[$params[$number - 1]] = $value;
         }
     }
     //loop again so we don't overwrite any params named in the route (like 'lang')
     foreach ($key_params as $param => $value) {
         if ($dispatcher->getParam($param) === null) {
             $dispatcher->setParam($param, $value);
         }
     }
 }
開發者ID:mrbubblesort,項目名稱:waitlist,代碼行數:27,代碼來源:Params.php

示例5: __construct

 public function __construct(Dispatcher $dispatcher, array $modules, $defaultLanguage = 'en')
 {
     $this->lang = $dispatcher->getParam('language');
     if (is_null($this->lang)) {
         $this->lang = $defaultLanguage;
     }
     $config = $dispatcher->getDI()->get('config');
     $translations = $this->getMessages($config->projectPath . 'common/');
     if (!is_array($translations)) {
         $translations = [];
     }
     $translationsModule = $this->getMessages($modules[$dispatcher->getModuleName()]);
     if (!is_array($translationsModule)) {
         $translationsModule = [];
     }
     $translations = array_merge($translations, $translationsModule);
     $this->translate = new NativeArray(['content' => $translations]);
 }
開發者ID:mirobrando,項目名稱:ng-phalcon,代碼行數:18,代碼來源:Translation.php

示例6: passThrouthMiddleWares

 public function passThrouthMiddleWares(Request $request, Response $response, Dispatcher $dispatcher)
 {
     $route = $this->getMatchedRoute();
     if (null == $route) {
         die('url is invalid, their is no matched route for this url!');
     }
     $pattern = $route->getPattern();
     //對每個路由都進行驗證的中間件! @todo 如果是get方式的話,目標對象如何獲取呢?當前用戶是否擁有該資源?
     foreach ($this->middlewaresForEveryRoute as $validator) {
         $data = null;
         if (preg_match('|.*:.*|', $validator)) {
             //此處設置了可以帶中間件參數
             list($validator, $data) = explode(':', $validator);
             $data = $dispatcher->getParam($data);
         }
         $validator = new $validator();
         if (!in_array($route->getName(), $validator->excludedRoutes) and !$validator->isValid($data)) {
             $url = $validator->getRedirectedUrl();
             //                    dd($url);
             $response->redirect($url, true);
             return false;
         }
     }
     //@todo 如果是get方式的如何過濾呢?應該如何設置才是正常的呢?例如get方式的search的過濾,單獨處理?也許吧?
     if ($this->hasMatchedMiddleWares($pattern) and $request->isPost()) {
         $middleWares = $this->getMiddleWares($pattern);
         foreach ($middleWares as $validator) {
             $data = $request->getPost();
             //                dd($validator);
             if (preg_match('|.*:.*|', $validator)) {
                 list($validator, $data) = explode(':', $validator);
                 $data = $dispatcher->getParam($data);
             }
             $validator = new $validator();
             if (!$validator->isValid($data)) {
                 $url = $validator->getRedirectedUrl();
                 //                    dd($url);
                 $response->redirect($url, true);
                 return false;
             }
         }
     }
     return true;
 }
開發者ID:huoybb,項目名稱:movie,代碼行數:44,代碼來源:myRouter.php

示例7: passThrouthMiddleWares

 public function passThrouthMiddleWares(Request $request, Response $response, Dispatcher $dispatcher)
 {
     $route = $this->getMatchedRoute();
     if (null == $route) {
         $r = $this->getDI()->get('router');
         $r->handle($request->getURI());
         $route = $r->getMatchedRoute();
         //為什麽搜索“裝備”會出現找不到路由的問題?估計與字符處理有關係
         if (null == $route) {
             die('url地址無效,找不到對應的路由設置!');
         }
     }
     $pattern = $route->getPattern();
     //對每個路由都進行驗證的中間件! @todo 如果是get方式的話,目標對象如何獲取呢?當前用戶是否擁有該資源?
     foreach ($this->middlewaresForEveryRoute as $validator) {
         $data = null;
         if (preg_match('|.*:.*|', $validator)) {
             //此處設置了可以帶中間件參數
             list($validator, $data) = explode(':', $validator);
             $data = $dispatcher->getParam($data);
         }
         /** @var myValidation $validator */
         $validator = new $validator();
         if (!in_array($route->getName(), $validator->excludedRoutes) and !$validator->isValid($data)) {
             $url = $validator->getRedirectedUrl();
             //                    dd($url);
             $response->redirect($url, true);
             return false;
         }
     }
     //@todo 如果是get方式的如何過濾呢?應該如何設置才是正常的呢?例如get方式的search的過濾,單獨處理?也許吧?
     if ($this->hasMatchedMiddleWares($pattern) and $request->isPost()) {
         $middleWares = $this->getMiddleWares($pattern);
         foreach ($middleWares as $validator) {
             $data = $request->getPost();
             //                dd($validator);
             if (preg_match('|[^:]+:[^:]+|', $validator)) {
                 list($validator, $data) = explode(':', $validator);
                 $data = $dispatcher->getParam($data);
             }
             if (preg_match('|.*Rules$|', $validator)) {
                 $rules = new $validator();
                 $validator = (new myValidation())->take($rules);
             } else {
                 $validator = new $validator();
             }
             if (!$validator->isValid($data)) {
                 $url = $validator->getRedirectedUrl();
                 //                    dd($url);
                 $response->redirect($url, true);
                 return false;
             }
         }
     }
     return true;
 }
開發者ID:huoybb,項目名稱:standard,代碼行數:56,代碼來源:myRouter.php


注:本文中的Phalcon\Mvc\Dispatcher::getParam方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。