本文整理汇总了PHP中Phalcon\Mvc\Dispatcher::setParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Dispatcher::setParams方法的具体用法?PHP Dispatcher::setParams怎么用?PHP Dispatcher::setParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Phalcon\Mvc\Dispatcher
的用法示例。
在下文中一共展示了Dispatcher::setParams方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpDispatcher
private function setUpDispatcher()
{
$this->dispatcher->setControllerName($this->router->getControllerName());
$this->dispatcher->setActionName($this->router->getActionName());
$this->dispatcher->setParams($this->router->getParams());
$oDispatcherEventManager = new Manager();
$oDispatcherEventManager->attach('dispatch:beforeDispatch', function (Event $oEvent, Dispatcher $oDispatcher, $data) {
return false;
});
$this->dispatcher->setEventsManager($oDispatcherEventManager);
}
示例2: beforeExecuteRoute
/**
* @param Dispatcher $dispatcher
*/
public function beforeExecuteRoute(Dispatcher $dispatcher)
{
$aParams = $dispatcher->getParams();
$aNewParams = array();
for ($i = 0; $i < count($aParams); $i = $i + 2) {
if (isset($aParams[$i + 1])) {
$aNewParams[$aParams[$i]] = $aParams[$i + 1];
}
}
$dispatcher->setParams(array_merge($aNewParams, $_GET, $this->getPost()));
}
示例3: setUp
/**
* Sets the test up by loading the DI container and other stuff
*
* @return Phalcon\DI
*/
protected function setUp()
{
parent::setUp();
// Set the dispatcher
$this->di->set('dispatcher', function () {
$dispatcher = new PhDispatcher();
$dispatcher->setControllerName('test');
$dispatcher->setActionName('empty');
$dispatcher->setParams(array());
return $dispatcher;
});
$this->di->set('escaper', function () {
return new PhEscaper();
});
}
示例4: testDispatcherParams
public function testDispatcherParams()
{
$dispatcher = new Dispatcher();
$interceptor = new DispatchInterceptor();
$this->assertEquals($interceptor->getInterceptorParams($dispatcher), array());
$dispatcher = new Dispatcher();
$dispatcher->setParams(array('_dispatch_cache' => 'lifetime=-1'));
$this->assertEquals($interceptor->getInterceptorParams($dispatcher), array());
$dispatcher = new Dispatcher();
$dispatcher->setParams(array('_dispatch_cache' => 'lifetime=60'));
$this->assertEquals($interceptor->getInterceptorParams($dispatcher), array('lifetime' => 60, 'methods' => array('get'), 'ignore_query_keys' => array('_'), 'jsonp_callback_key' => 'callback', 'format' => 'text'));
$dispatcher = new Dispatcher();
$dispatcher->setParams(array('_dispatch_cache' => 'lifetime=100&methods=get|post&ignore_query_keys=api_key|_&jsonp_callback_key=callback&format=jsonp'));
$this->assertEquals($interceptor->getInterceptorParams($dispatcher), array('lifetime' => 100, 'methods' => array('get', 'post'), 'ignore_query_keys' => array('api_key', '_'), 'jsonp_callback_key' => 'callback', 'format' => 'jsonp'));
}
示例5: setUp
/**
* Sets the test up by loading the DI container and other stuff
*
* @param \Phalcon\DiInterface $di
* @param \Phalcon\Config $config
* @return void
*/
protected function setUp(\Phalcon\DiInterface $di = null, \Phalcon\Config $config = null)
{
parent::setUp($di, $config);
// Set the dispatcher
$this->di->setShared('dispatcher', function () {
$dispatcher = new PhDispatcher();
$dispatcher->setControllerName('test');
$dispatcher->setActionName('empty');
$dispatcher->setParams(array());
return $dispatcher;
});
$this->di->set('escaper', function () {
return new PhEscaper();
});
if ($this->di instanceof \Phalcon\DiInterface) {
$this->application = new PhApplication($this->di);
}
}
示例6: setUp
/**
* This method is called before a test is executed.
*/
protected function setUp()
{
parent::setUp();
// Set the dispatcher
$this->di->setShared('dispatcher', function () {
$dispatcher = new PhDispatcher();
$dispatcher->setControllerName('test');
$dispatcher->setActionName('empty');
$dispatcher->setParams([]);
return $dispatcher;
});
$this->di->set('escaper', function () {
return new PhEscaper();
});
if ($this->di instanceof DiInterface) {
$this->application = new PhApplication($this->di);
}
}
示例7: registerServices
/**
* Register the services here to make them general or register in the
* ModuleDefinition to make them module-specific
*/
public function registerServices($di)
{
//Registering a dispatcher
$di['dispatcher'] = function () {
$dispatcher = new PhDispatcher();
//Attach a event listener to the dispatcher
$eventManager = new PhEveManager();
//Notfound redirect
// $eventManager->attach('dispatch:beforeException', function($event, $dispatcher, $exception) {
// //Alternative way, controller or action doesn't exist
// if ($event->getType() == 'beforeException') {
// switch ($exception->getCode()) {
// case PhDispatcher::EXCEPTION_HANDLER_NOT_FOUND:
// case PhDispatcher::EXCEPTION_ACTION_NOT_FOUND:
// $dispatcher->forward([
// 'module' => 'admin',
// 'controller' => 'notfound'
// ]);
// return false;
// }
// }
// });
//attach get param after controller as key/value
$eventManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) {
$keyParams = [];
$params = $dispatcher->getParams();
//Use odd parameters as keys and even as values
foreach ($params as $number => $value) {
if ($number & 1) {
$keyParams[$params[$number - 1]] = $value;
}
}
//Override parameters
$dispatcher->setParams($keyParams);
});
// Authorization
$eventManager->attach('dispatch', new \Fly\Authorization('admin'));
$dispatcher->setEventsManager($eventManager);
$dispatcher->setDefaultNamespace('Controller\\Admin');
return $dispatcher;
};
$di['view']->setViewsDir(ROOT_PATH . '/modules/admin/views/');
}
示例8: array
$keyParams = array();
$params = $dispatcher->getParams();
foreach ($params as $number => $value) {
/*
// Use odd parameters as keys and even as values
if ($number & 1) {
$keyParams[$params[$number - 1]] = $value;
}
//*/
// Explode each parameter as key,value pairs
/*
$parts = explode(':', $value);
$keyParams[$parts[0]] = $parts[1];
//*/
}
$dispatcher->setParams($keyParams);
});
// Handling Not-Found Exceptions
$eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
//Handle 404 exceptions
if ($exception instanceof DispatchException) {
$dispatcher->forward(array('controller' => 'index', 'action' => 'show404'));
return false;
}
//Alternative way, controller or action doesn't exist
if ($event->getType() == 'beforeException') {
switch ($exception->getCode()) {
case \Phalcon\Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
case \Phalcon\Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
$dispatcher->forward(array('controller' => 'index', 'action' => 'show404'));
return false;