当前位置: 首页>>代码示例>>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;未经允许,请勿转载。