本文整理汇总了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);
}
}
}
示例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);
}
示例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;
}