当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::addParams方法代码示例

本文整理汇总了PHP中Cake\Network\Request::addParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::addParams方法的具体用法?PHP Request::addParams怎么用?PHP Request::addParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Network\Request的用法示例。


在下文中一共展示了Request::addParams方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testBeforeDispatch

 /**
  * testBeforeDispatch
  *
  * @return void
  */
 public function testBeforeDispatch()
 {
     Configure::write('App.namespace', 'TestApp');
     $filter = new ControllerFactoryFilter();
     $request = new Request();
     $response = new Response();
     $request->addParams(['prefix' => 'admin', 'controller' => 'Posts', 'action' => 'index']);
     $event = new Event(__CLASS__, $this, compact('request', 'response'));
     $filter->beforeDispatch($event);
     $this->assertEquals('TestApp\\Controller\\Admin\\PostsController', get_class($event->data['controller']));
     $request->addParams(['prefix' => 'admin/sub', 'controller' => 'Posts', 'action' => 'index']);
     $event = new Event(__CLASS__, $this, compact('request', 'response'));
     $filter->beforeDispatch($event);
     $this->assertEquals('TestApp\\Controller\\Admin\\Sub\\PostsController', get_class($event->data['controller']));
 }
开发者ID:jdaosavanh,项目名称:clickerwebapp,代码行数:20,代码来源:ControllerFactoryFilterTest.php

示例2: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Router::connect('/:controller/:action');
     $request = new Request();
     $request->addParams(array('controller' => 'pages', 'action' => 'display'));
     $this->View = new View($request);
     $this->Toolbar = new ToolbarHelper($this->View);
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:14,代码来源:ToolbarHelperTest.php

示例3: testAuthorizeCheckFailure

 /**
  * test check() failing
  *
  * @return void
  */
 public function testAuthorizeCheckFailure()
 {
     $request = new Request('posts/index');
     $request->addParams(['controller' => 'posts', 'action' => 'index']);
     $user = ['Users' => ['username' => 'mark']];
     $this->_mockAcl();
     $this->Acl->expects($this->once())->method('check')->with($user, 'Posts', 'read')->will($this->returnValue(false));
     $this->assertFalse($this->auth->authorize($user['Users'], $request));
 }
开发者ID:cakephp,项目名称:acl,代码行数:14,代码来源:CrudAuthorizeTest.php

示例4: testBeforeDispatchSkipWhenControllerSet

 /**
  * test setting parameters in beforeDispatch method
  *
  * @return void
  * @triggers __CLASS__ $this, compact(request)
  */
 public function testBeforeDispatchSkipWhenControllerSet()
 {
     $filter = new RoutingFilter();
     $request = new Request("/testcontroller/testaction/params1/params2/params3");
     $request->addParams(['controller' => 'articles']);
     $event = new Event(__CLASS__, $this, compact('request'));
     $filter->beforeDispatch($event);
     $this->assertSame($request->params['controller'], 'articles');
     $this->assertEmpty($request->params['action']);
 }
开发者ID:Slayug,项目名称:castor,代码行数:16,代码来源:RoutingFilterTest.php

示例5: check

 /**
  * Check if the user can access to the given URL.
  *
  * @param array $params The params to check.
  *
  * @return bool
  */
 public function check(array $params = [])
 {
     if (!$this->request->session()->read('Auth.User')) {
         return false;
     }
     $params += ['_base' => false];
     $url = Router::url($params);
     $params = Router::parse($url);
     $user = [$this->Authorize->config('userModel') => $this->request->session()->read('Auth.User')];
     $request = new Request();
     $request->addParams($params);
     $action = $this->Authorize->action($request);
     return $this->Acl->check($user, $action);
 }
开发者ID:Xety,项目名称:Xeta,代码行数:21,代码来源:AclHelper.php

示例6: requestAction


//.........这里部分代码省略.........
  *   'query' => ['page' => 1],
  *   'cookies' => ['remember_me' => 1],
  * ]);
  * ```
  *
  * ### Sending environment or header values
  *
  * By default actions dispatched with this method will use the global $_SERVER and $_ENV
  * values. If you want to override those values for a request action, you can specify the values:
  *
  * ```
  * $vars = $this->requestAction('/articles/popular', [
  *   'environment' => ['CONTENT_TYPE' => 'application/json']
  * ]);
  * ```
  *
  * ### Transmitting the session
  *
  * By default actions dispatched with this method will use the standard session object.
  * If you want a particular session instance to be used, you need to specify it.
  *
  * ```
  * $vars = $this->requestAction('/articles/popular', [
  *   'session' => new Session($someSessionConfig)
  * ]);
  * ```
  *
  * @param string|array $url String or array-based url.  Unlike other url arrays in CakePHP, this
  *    url will not automatically handle passed arguments in the $url parameter.
  * @param array $extra if array includes the key "return" it sets the autoRender to true.  Can
  *    also be used to submit GET/POST data, and passed arguments.
  * @return mixed Boolean true or false on success/failure, or contents
  *    of rendered action if 'return' is set in $extra.
  * @deprecated 3.3.0 You should refactor your code to use View Cells instead of this method.
  */
 public function requestAction($url, array $extra = [])
 {
     if (empty($url)) {
         return false;
     }
     if (($index = array_search('return', $extra)) !== false) {
         $extra['return'] = 0;
         $extra['autoRender'] = 1;
         unset($extra[$index]);
     }
     $extra += ['autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1];
     $baseUrl = Configure::read('App.fullBaseUrl');
     if (is_string($url) && strpos($url, $baseUrl) === 0) {
         $url = Router::normalize(str_replace($baseUrl, '', $url));
     }
     if (is_string($url)) {
         $params = ['url' => $url];
     } elseif (is_array($url)) {
         $defaultParams = ['plugin' => null, 'controller' => null, 'action' => null];
         $params = ['params' => $url + $defaultParams, 'base' => false, 'url' => Router::reverse($url)];
         if (empty($params['params']['pass'])) {
             $params['params']['pass'] = [];
         }
     }
     $current = Router::getRequest();
     if ($current) {
         $params['base'] = $current->base;
         $params['webroot'] = $current->webroot;
     }
     $params['post'] = $params['query'] = [];
     if (isset($extra['post'])) {
         $params['post'] = $extra['post'];
     }
     if (isset($extra['query'])) {
         $params['query'] = $extra['query'];
     }
     if (isset($extra['cookies'])) {
         $params['cookies'] = $extra['cookies'];
     }
     if (isset($extra['environment'])) {
         $params['environment'] = $extra['environment'] + $_SERVER + $_ENV;
     }
     unset($extra['environment'], $extra['post'], $extra['query']);
     $params['session'] = isset($extra['session']) ? $extra['session'] : new Session();
     $request = new Request($params);
     $request->addParams($extra);
     $dispatcher = DispatcherFactory::create();
     // If an application is using PSR7 middleware,
     // we need to 'fix' their missing dispatcher filters.
     $needed = ['routing' => RoutingFilter::class, 'controller' => ControllerFactoryFilter::class];
     foreach ($dispatcher->filters() as $filter) {
         if ($filter instanceof RoutingFilter) {
             unset($needed['routing']);
         }
         if ($filter instanceof ControllerFactoryFilter) {
             unset($needed['controller']);
         }
     }
     foreach ($needed as $class) {
         $dispatcher->addFilter(new $class());
     }
     $result = $dispatcher->dispatch($request, new Response());
     Router::popRequest();
     return $result;
 }
开发者ID:nrother,项目名称:cakephp,代码行数:101,代码来源:RequestActionTrait.php

示例7: testIsRequested

 /**
  * Test is('requested') and isRequested()
  *
  * @return void
  */
 public function testIsRequested()
 {
     $request = new Request();
     $request->addParams(['controller' => 'posts', 'action' => 'index', 'plugin' => null, 'requested' => 1]);
     $this->assertTrue($request->is('requested'));
     $this->assertTrue($request->isRequested());
     $request = new Request();
     $request->addParams(['controller' => 'posts', 'action' => 'index', 'plugin' => null]);
     $this->assertFalse($request->is('requested'));
     $this->assertFalse($request->isRequested());
 }
开发者ID:alexunique0519,项目名称:Blog_Cakephp_association,代码行数:16,代码来源:RequestTest.php

示例8: testAuthenticateFailReChallenge

    /**
     * test scope failure.
     *
     * @expectedException \Cake\Network\Exception\UnauthorizedException
     * @expectedExceptionCode 401
     * @return void
     */
    public function testAuthenticateFailReChallenge()
    {
        $this->auth->config('scope.username', 'nate');
        $request = new Request(['url' => 'posts/index', 'environment' => ['REQUEST_METHOD' => 'GET']]);
        $request->addParams(array('pass' => array()));
        $digest = <<<DIGEST
Digest username="mariano",
realm="localhost",
nonce="123",
uri="/dir/index.html",
qop=auth,
nc=1,
cnonce="123",
response="6629fae49393a05397450978507c4ef1",
opaque="123abc"
DIGEST;
        $request->env('PHP_AUTH_DIGEST', $digest);
        $this->auth->unauthenticated($request, $this->response);
    }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:26,代码来源:DigestAuthenticateTest.php

示例9: testActionWithPrefix

 public function testActionWithPrefix()
 {
     $request = new Request('/admin/posts/index');
     $request->addParams(['plugin' => null, 'prefix' => 'admin', 'controller' => 'posts', 'action' => 'index']);
     $result = $this->auth->action($request);
     $this->assertEquals('controllers/admin/Posts/index', $result);
 }
开发者ID:rochamarcelo,项目名称:acl,代码行数:7,代码来源:ActionsAuthorizeTest.php

示例10: testDefaultToLoginRedirect

 /**
  * Default to loginRedirect, if set, on authError.
  *
  * @return void
  * @triggers Controller.startup $Controller
  */
 public function testDefaultToLoginRedirect()
 {
     $url = '/party/on';
     $this->Auth->request = $request = new Request($url);
     $request->env('HTTP_REFERER', false);
     $request->addParams(Router::parse($url));
     $request->addPaths(['base' => 'dirname', 'webroot' => '/dirname/']);
     Router::pushRequest($request);
     $this->Auth->config('authorize', ['Controller']);
     $this->Auth->setUser(['username' => 'mariano', 'password' => 'cake']);
     $this->Auth->config('loginRedirect', ['controller' => 'something', 'action' => 'else']);
     $response = new Response();
     $Controller = $this->getMock('Cake\\Controller\\Controller', ['on', 'redirect'], [$request, $response]);
     $event = new Event('Controller.startup', $Controller);
     // Should not contain basedir when redirect is called.
     $expected = '/something/else';
     $Controller->expects($this->once())->method('redirect')->with($this->equalTo($expected));
     $this->Auth->startup($event);
 }
开发者ID:Rabp9,项目名称:test-psi2,代码行数:25,代码来源:AuthComponentTest.php

示例11: testParseNamedParameters

 /**
  * Test that the compatibility method for incoming urls works.
  *
  * @return void
  */
 public function testParseNamedParameters()
 {
     $request = new Request();
     $request->addParams(array('controller' => 'posts', 'action' => 'index'));
     $result = Router::parseNamedParams($request);
     $this->assertSame([], $result->params['named']);
     $request = new Request();
     $request->addParams(array('controller' => 'posts', 'action' => 'index', 'pass' => array('home', 'one:two', 'three:four', 'five[nested][0]:six', 'five[nested][1]:seven')));
     Router::parseNamedParams($request);
     $expected = array('plugin' => null, 'controller' => 'posts', 'action' => 'index', '_ext' => null, 'pass' => array('home'), 'named' => array('one' => 'two', 'three' => 'four', 'five' => array('nested' => array('six', 'seven'))));
     $this->assertEquals($expected, $request->params);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:17,代码来源:RouterTest.php

示例12: testViewPathConventions

 /**
  * test that a classes namespace is used in the viewPath.
  *
  * @return void
  */
 public function testViewPathConventions()
 {
     $request = new Request('admin/posts');
     $request->addParams(['prefix' => 'admin']);
     $response = $this->getMock('Cake\\Network\\Response');
     $Controller = new \TestApp\Controller\Admin\PostsController($request, $response);
     $this->assertEquals('Admin' . DS . 'Posts', $Controller->viewPath);
     $request->addParams(['prefix' => 'admin/super']);
     $response = $this->getMock('Cake\\Network\\Response');
     $Controller = new \TestApp\Controller\Admin\PostsController($request, $response);
     $this->assertEquals('Admin' . DS . 'Super' . DS . 'Posts', $Controller->viewPath);
     $request = new Request('pages/home');
     $Controller = new \TestApp\Controller\PagesController($request, $response);
     $this->assertEquals('Pages', $Controller->viewPath);
 }
开发者ID:ringiait,项目名称:portal,代码行数:20,代码来源:ControllerTest.php

示例13: hasPermission

 /**
  * Checks if the given user has permission to perform an action.
  *
  * @param array $params The params to check.
  *
  * @return string
  */
 public function hasPermission(array $params = [])
 {
     $params += ['controller' => 'Permissions', '_base' => false, 'prefix' => 'chat'];
     $url = Router::url($params);
     $params = Router::parse($url);
     $request = new Request();
     $request->addParams($params);
     $action = $this->Authorize->action($request);
     $user = [$this->Authorize->config('userModel') => $this->_session->read('Auth.User')];
     return $this->Acl->check($user, $action);
 }
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:18,代码来源:ChatComponent.php

示例14: testNumbersRouting

 /**
  * test numbers() with routing parameters.
  *
  * @return void
  */
 public function testNumbersRouting()
 {
     $this->Paginator->request->params['paging'] = array('Client' => array('page' => 2, 'current' => 2, 'count' => 30, 'prevPage' => false, 'nextPage' => 3, 'pageCount' => 3));
     $request = new Request();
     $request->addParams(array('controller' => 'clients', 'action' => 'index', 'plugin' => null));
     $request->base = '';
     $request->here = '/clients/index?page=2';
     $request->webroot = '/';
     Router::setRequestInfo($request);
     $result = $this->Paginator->numbers();
     $expected = array(array('li' => array()), array('a' => array('href' => '/clients/index')), '1', '/a', '/li', array('li' => array('class' => 'active')), '<span', '2', '/span', '/li', array('li' => array()), array('a' => array('href' => '/clients/index?page=3')), '3', '/a', '/li');
     $this->assertTags($result, $expected);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:18,代码来源:PaginatorHelperTest.php

示例15: testAuthenticateWithBlowfish

 /**
  * testAuthenticateWithBlowfish
  *
  * @return void
  */
 public function testAuthenticateWithBlowfish()
 {
     $hash = Security::hash('password', 'blowfish');
     $this->skipIf(strpos($hash, '$2a$') === false, 'Skipping blowfish tests as hashing is not working');
     $request = new Request(['url' => 'posts/index', 'environment' => ['PHP_AUTH_USER' => 'mariano', 'PHP_AUTH_PW' => 'password']]);
     $request->addParams(array('pass' => array()));
     $User = TableRegistry::get('Users');
     $User->updateAll(array('password' => $hash), array('username' => 'mariano'));
     $this->auth->config('passwordHasher', 'Blowfish');
     $result = $this->auth->authenticate($request, $this->response);
     $expected = array('id' => 1, 'username' => 'mariano', 'created' => new Time('2007-03-17 01:16:23'), 'updated' => new Time('2007-03-17 01:18:31'));
     $this->assertEquals($expected, $result);
 }
开发者ID:ripzappa0924,项目名称:carte0.0.1,代码行数:18,代码来源:BasicAuthenticateTest.php


注:本文中的Cake\Network\Request::addParams方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。