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


PHP Dispatcher::setParam方法代碼示例

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


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

示例1: 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

示例2: action

 /**
  * @param \Phalcon\Events\Event $event
  * @param \Phalcon\Mvc\Dispatcher $dispatcher
  * @param array $params
  * @return mixed
  */
 public function action(Event $event, Dispatcher $dispatcher, $params)
 {
     $controller = $dispatcher->getControllerName();
     $action = $dispatcher->getActionName();
     $key = $controller . '/' . $action;
     // $cname = $dispatcher->getDI()->get(AppConstant::DI_SERVICE_API)->getApiClass($key);
     //非注冊Api,不需要做校驗
     // if ($cname == null) return;
     $cname = 'Account\\register';
     $c = new \ReflectionClass($cname);
     $object = $c->newInstance();
     //賦值
     $this->arrToObj($object, $params);
     $this->validate($cname, $object);
     $dispatcher->setParam(AppConstant::HTTP_PROTOCOL_DATA, $object);
 }
開發者ID:huxiaohe,項目名稱:api-framework,代碼行數:22,代碼來源:ValidateInterceptor.php

示例3: beforeExecuteRoute

 /**
  * @param Event $event
  * @param Dispatcher $dispatcher
  * @return bool
  */
 public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
 {
     $role = 'guest';
     if ($this->session->has('user_id')) {
         $userId = $this->session->get('user_id');
         if ($userId) {
             $user = User::findFirst($userId);
             if ($user instanceof User) {
                 $role = 'user';
                 $dispatcher->setParam('user', $user);
             }
         }
     }
     $controller = strtolower($dispatcher->getControllerName());
     $action = strtolower($dispatcher->getActionName());
     if (!$this->acl->isAllowed($role, $controller, $action)) {
         $this->session->set('__callback_url', $this->request->getServer('REQUEST_URI'));
         $dispatcher->forward(['controller' => 'auth', 'action' => 'signIn']);
         return false;
     }
     return true;
 }
開發者ID:tankist,項目名稱:blog-mvc,代碼行數:27,代碼來源:Auth.php


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