本文整理汇总了PHP中Router::setRequestInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::setRequestInfo方法的具体用法?PHP Router::setRequestInfo怎么用?PHP Router::setRequestInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Router
的用法示例。
在下文中一共展示了Router::setRequestInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadRouter
public function loadRouter($base = null)
{
if ($base === null) {
$base = Configure::read('App.base');
}
if (!class_exists('Router')) {
App::import('Core', 'Router');
}
Router::setRequestInfo(array(array(), array('base' => $base, 'webroot' => $base)));
if (!defined('FULL_BASE_URL')) {
$s = null;
if (env('HTTPS')) {
$s = 's';
}
$httpHost = env('HTTP_HOST');
if (empty($httpHost)) {
$httpHost = env('SERVER_NAME');
if (empty($httpHost)) {
if (class_exists('Environment')) {
$httpHost = Environment::getHostName();
}
}
}
if (!empty($httpHost)) {
define('FULL_BASE_URL', 'http' . $s . '://' . $httpHost);
}
}
}
示例2: _getRequest
/**
* 指定されたURLに対応しRouterパース済のCakeRequestのインスタンスを返す
*
* @param string $url URL
* @return CakeRequest
*/
protected function _getRequest($url)
{
Router::reload();
$request = new CakeRequest($url);
// コンソールからのテストの場合、requestのパラメーターが想定外のものとなってしまうので調整
if (isConsole()) {
$baseUrl = Configure::read('App.baseUrl');
if ($request->url === false) {
$request->here = $baseUrl . '/';
} elseif (preg_match('/^' . preg_quote($request->webroot, '/') . '/', $request->here)) {
$request->here = $baseUrl . '/' . preg_replace('/^' . preg_quote($request->webroot, '/') . '/', '', $request->here);
}
if ($baseUrl) {
if (preg_match('/^\\//', $baseUrl)) {
$request->base = $baseUrl;
} else {
$request->base = '/' . $baseUrl;
}
$request->webroot = $baseUrl;
} else {
$request->base = '';
$request->webroot = '/';
}
}
Router::setRequestInfo($request);
$params = Router::parse($request->url);
$request->addParams($params);
return $request;
}
示例3: setUp
/**
* SetUp method
*
* @return void
*/
public function setUp()
{
parent::setUp();
Configure::write('Config.language', 'deu');
Configure::delete('Passwordable');
Configure::write('Passwordable.auth', 'AuthTest');
$this->User = ClassRegistry::init('Tools.ToolsUser');
if (isset($this->User->validate['pwd'])) {
unset($this->User->validate['pwd']);
}
if (isset($this->User->validate['pwd_repeat'])) {
unset($this->User->validate['pwd_repeat']);
}
if (isset($this->User->validate['pwd_current'])) {
unset($this->User->validate['pwd_current']);
}
if (isset($this->User->order)) {
unset($this->User->order);
}
$this->User->create();
$data = ['id' => '5', 'name' => 'admin', 'password' => Security::hash('somepwd', null, true), 'role_id' => '1'];
$this->User->set($data);
$result = $this->User->save();
$this->assertTrue((bool) $result);
Router::setRequestInfo(new CakeRequest(null, false));
}
示例4: testIs
public function testIs()
{
$result = Reveal::is('App.online');
$expected = !in_array(gethostbyname('google.com'), array('google.com', false));
$this->assertEqual($result, $expected);
$result = Reveal::is('DebugKit.loaded');
$expected = CakePlugin::loaded('DebugKit');
$this->assertEqual($result, $expected);
$result = Reveal::is(array('OR' => array('DebugKit.enabled', 'DebugKit.automated')));
$expected = Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun');
$this->assertEqual($result, $expected);
$_GET['debug'] = 'true';
$this->assertTrue(Reveal::is('DebugKit.requested'));
$result = Reveal::is('DebugKit.loaded', array('OR' => array('DebugKit.enabled', array('AND' => array('DebugKit.automated', 'DebugKit.requested')))));
$expected = CakePlugin::loaded('DebugKit') || Configure::read('debug') || Configure::read('DebugKit.forceEnable') || Configure::read('DebugKit.autoRun') && isset($_GET['debug']) && 'true' == $_GET['debug'];
$this->assertEqual($result, $expected);
$this->assertEqual(Reveal::is('DebugKit.running'), $expected);
$request = new CakeRequest();
Router::setRequestInfo($request->addParams(array('controller' => 'pages', 'action' => 'display', 'pass' => array('home'))));
$result = Reveal::is('Page.front');
$this->assertTrue($result);
Router::reload();
$request = new CakeRequest();
Router::setRequestInfo($request->addParams(array('prefix' => 'admin', 'admin' => true)));
$result = Reveal::is('Page.prefixed');
$this->assertTrue($result);
Router::reload();
$request = new CakeRequest();
Router::setRequestInfo($request->addParams(array('controller' => 'users', 'action' => 'login')));
$result = Reveal::is('Page.login');
$this->assertTrue($result);
$this->assertTrue(Reveal::is('Page.test'));
}
示例5: __construct
/**
* construct method
*
*/
public function __construct($request, $response)
{
$request->addParams(Router::parse('/seo_test'));
$request->here = '/seo_test';
$request->webroot = '/';
Router::setRequestInfo($request);
parent::__construct($request, $response);
}
示例6: testIncludeAssets
/**
* test that assets only have one base path attached
*
* @return void
*/
function testIncludeAssets()
{
Router::setRequestInfo(array(array('controller' => 'posts', 'action' => 'index', 'plugin' => null), array('base' => '/some/dir', 'webroot' => '/some/dir/', 'here' => '/some/dir/posts')));
$this->Helper->Html->webroot = '/some/dir/';
$this->Helper->script('one.js');
$result = $this->Helper->includeAssets();
$this->assertPattern('#"/some/dir/asset_compress#', $result, 'double dir set %s');
}
示例7: setUp
/**
* setup create a request object to get out of router later.
*
* @return void
*/
public function setUp()
{
parent::setUp();
App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)), App::RESET);
Router::reload();
$request = new CakeRequest(null, false);
$request->base = '';
Router::setRequestInfo($request);
Configure::write('debug', 2);
}
示例8: setUp
/**
* setup create a request object to get out of router later.
*
* @return void
*/
public function setUp()
{
App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)), true);
Router::reload();
$request = new CakeRequest(null, false);
$request->base = '';
Router::setRequestInfo($request);
$this->_debug = Configure::read('debug');
$this->_error = Configure::read('Error');
Configure::write('debug', 2);
}
示例9: setUp
/**
* setup create a request object to get out of router later.
*
* @return void
*/
function setUp()
{
App::build(array('views' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS, TEST_CAKE_CORE_INCLUDE_PATH . 'libs' . DS . 'view' . DS)), true);
Router::reload();
$request = new CakeRequest(null, false);
$request->base = '';
Router::setRequestInfo($request);
$this->_debug = Configure::read('debug');
$this->_error = Configure::read('Error');
Configure::write('debug', 2);
}
示例10: setUp
/**
* setup create a request object to get out of router later.
*
* @return void
*/
public function setUp()
{
parent::setUp();
App::build(array('View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)), App::RESET);
Router::reload();
$request = new CakeRequest(NULL, FALSE);
$request->base = '';
Router::setRequestInfo($request);
Configure::write('debug', 2);
CakeLog::disable('stdout');
CakeLog::disable('stderr');
}
示例11: dispatch
/**
* Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set
* to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
*
* Actions in CakePHP can be any public method on a controller, that is not declared in Controller. If you
* want controller methods to be public and in-accessible by URL, then prefix them with a `_`.
* For example `public function _loadPosts() { }` would not be accessible via URL. Private and protected methods
* are also not accessible via URL.
*
* If no controller of given name can be found, invoke() will throw an exception.
* If the controller is found, and the action is not found an exception will be thrown.
*
* @param CakeRequest $request Request object to dispatch.
* @param CakeResponse $response Response object to put the results of the dispatch into.
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
* @return boolean Success
* @throws MissingControllerException When the controller is missing.
*/
public function dispatch(CakeRequest $request, CakeResponse $response, $additionalParams = array())
{
if ($this->asset($request->url, $response) || $this->cached($request->here())) {
return;
}
Router::setRequestInfo($request);
$request = $this->parseParams($request, $additionalParams);
$controller = $this->_getController($request, $response);
if (!$controller instanceof Controller) {
throw new MissingControllerException(array('class' => Inflector::camelize($request->params['controller']) . 'Controller', 'plugin' => empty($request->params['plugin']) ? null : Inflector::camelize($request->params['plugin'])));
}
return $this->_invoke($controller, $request, $response);
}
示例12: testSortLinks
function testSortLinks()
{
Router::reload();
Router::parse('/');
Router::setRequestInfo(array(array('plugin' => null, 'controller' => 'accounts', 'action' => 'index', 'pass' => array(), 'form' => array(), 'url' => array('url' => 'accounts/', 'mod_rewrite' => 'true'), 'bare' => 0), array('plugin' => null, 'controller' => null, 'action' => null, 'base' => '/officespace', 'here' => '/officespace/accounts/', 'webroot' => '/officespace/', 'passedArgs' => array())));
$this->Paginator->options(array('url' => array('param')));
$result = $this->Paginator->sort('title');
$this->assertPattern('/\\/accounts\\/index\\/param\\/page:1\\/sort:title\\/direction:asc"\\s*>Title<\\/a>$/', $result);
$result = $this->Paginator->sort('date');
$this->assertPattern('/\\/accounts\\/index\\/param\\/page:1\\/sort:date\\/direction:desc"\\s*>Date<\\/a>$/', $result);
$result = $this->Paginator->numbers(array('modulus' => '2', 'url' => array('controller' => 'projects', 'action' => 'sort'), 'update' => 'list'));
$this->assertPattern('/\\/projects\\/sort\\/page:2/', $result);
$this->assertPattern('/<script type="text\\/javascript">Event.observe/', $result);
}
示例13: setUp
/**
* setup
*
* @return void
*/
public function setUp()
{
parent::setUp();
$this->request = new CakeRequest('posts/index', false);
Router::setRequestInfo($this->request);
$this->Collection = new ComponentCollection();
$this->Collection->load('Cookie');
$this->Collection->load('Session');
$this->auth = new CookieAuthenticate($this->Collection, array('fields' => array('username' => 'user', 'password' => 'password'), 'userModel' => 'MultiUser'));
$password = Security::hash('password', null, true);
$User = ClassRegistry::init('MultiUser');
$User->updateAll(array('password' => $User->getDataSource()->value($password)));
$this->response = $this->getMock('CakeResponse');
}
示例14: testGetUrl
/**
* testGetUrl
*
* $param string $host ホスト名
* $param string $ua ユーザーエージェント名
* @param string $url 変換前URL
* @param boolean $full フルURLで出力するかどうか
* @param boolean $useSubDomain サブドメインを利用するかどうか
* @param string $expects 期待するURL
* @dataProvider getUrlDataProvider
*/
public function testGetUrl($host, $ua, $url, $full, $useSubDomain, $expects)
{
$siteUrl = Configure::read('BcEnv.siteUrl');
Configure::write('BcEnv.siteUrl', 'http://main.com');
if ($ua) {
$_SERVER['HTTP_USER_AGENT'] = $ua;
}
if ($host) {
$_SERVER['HTTP_HOST'] = $host;
}
Router::setRequestInfo($this->_getRequest('/m/'));
$result = $this->Content->getUrl($url, $full, $useSubDomain);
$this->assertEquals($result, $expects);
Configure::write('BcEnv.siteUrl', $siteUrl);
}
示例15: dispatch
/**
* Dispatches and invokes given Request, handing over control to the involved controller. If the controller is set
* to autoRender, via Controller::$autoRender, then Dispatcher will render the view.
*
* Actions in CakePHP can be any public method on a controller, that is not declared in Controller. If you
* want controller methods to be public and in-accesible by URL, then prefix them with a `_`.
* For example `public function _loadPosts() { }` would not be accessible via URL. Private and protected methods
* are also not accessible via URL.
*
* If no controller of given name can be found, invoke() will throw an exception.
* If the controller is found, and the action is not found an exception will be thrown.
*
* @param CakeRequest $request Request object to dispatch.
* @param array $additionalParams Settings array ("bare", "return") which is melded with the GET and POST params
* @return boolean Success
* @throws MissingControllerException, MissingActionException, PrivateActionException if any of those error states
* are encountered.
*/
public function dispatch(CakeRequest $request, $additionalParams = array())
{
if ($this->asset($request->url) || $this->cached($request->here)) {
return;
}
$request = $this->parseParams($request, $additionalParams);
Router::setRequestInfo($request);
$controller = $this->_getController($request);
if (!$controller instanceof Controller) {
throw new MissingControllerException(array('controller' => Inflector::camelize($request->params['controller']) . 'Controller'));
}
if ($this->_isPrivateAction($request)) {
throw new PrivateActionException(array('controller' => Inflector::camelize($request->params['controller']) . "Controller", 'action' => $request->params['action']));
}
return $this->_invoke($controller, $request);
}