to() public method

Overrides lithium\net\http\Request::to() to provide the correct options for generating URLs. For information about this method, see the parent implementation.
See also: lithium\net\http\Request::to()
public to ( string $format, array $options = [] ) : mixed
$format string The format to convert to.
$options array Override options.
return mixed The return value type depends on `$format`.
Example #1
0
 /**
  * Tests that `action\Request` correctly inherits the functionality of the `to()` method
  * inherited from `lithium\net\http\Request`.
  */
 public function testConvertToUrl()
 {
     $request = new Request(array('env' => array('HTTP_HOST' => 'foo.com', 'HTTPS' => 'on'), 'base' => '/the/base/path', 'url' => '/the/url', 'query' => array('some' => 'query', 'parameter' => 'values')));
     $expected = 'https://foo.com/the/base/path/the/url?some=query&parameter=values';
     $this->assertEqual($expected, $request->to('url'));
 }
Example #2
0
 public function testConvertToStringWithJson()
 {
     $expected = join("\r\n", array('GET /posts HTTP/1.1', 'Host: lithify.me', 'Connection: Close', 'User-Agent: Mozilla/5.0', 'Content-Type: application/json', 'Content-Length: 36', '', '{"some":"body","parameter":"values"}'));
     $request = new Request(array('env' => array('HTTP_HOST' => 'lithify.me', 'CONTENT_TYPE' => 'application/json', 'HTTP_USER_AGENT' => 'Mozilla/5.0'), 'url' => '/posts', 'body' => '{"some":"body","parameter":"values"}'));
     $this->assertEqual($expected, $request->to('string'));
     $request = new Request(array('env' => array('HTTP_HOST' => 'lithify.me', 'CONTENT_TYPE' => 'application/json', 'HTTP_USER_AGENT' => 'Mozilla/5.0'), 'url' => '/posts', 'data' => array('some' => 'body', 'parameter' => 'values')));
     $this->assertEqual($expected, $request->to('string'));
 }