CakeRequest PHP Class Code Examples

This page contains top rated real world PHP examples of class CakeRequest extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: Object.php Project: MrGrigorev/reserva-de-salas
0
 /**
  * Calls a controller's method from any location. Can be used to connect controllers together
  * or tie plugins into a main application. requestAction can be used to return rendered views
  * or fetch the return value from controller actions.
  *
  * Under the hood this method uses Router::reverse() to convert the $url parameter into a string
  * URL.  You should use URL formats that are compatible with Router::reverse()
  *
  * #### Passing POST and GET data
  *
  * POST and GET data can be simulated in requestAction.  Use `$extra['url']` for
  * GET data.  The `$extra['data']` parameter allows POST data simulation.
  *
  * @param mixed $url String or array-based url.  Unlike other url arrays in CakePHP, this
  *    url will not automatically handle passed and named 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 named/passed arguments.
  * @return mixed Boolean true or false on success/failure, or contents
  *    of rendered action if 'return' is set in $extra.
  */
 public function requestAction($url, $extra = array())
 {
     if (empty($url)) {
         return false;
     }
     App::uses('Dispatcher', 'Routing');
     if (($index = array_search('return', $extra)) !== false) {
         $extra['return'] = 0;
         $extra['autoRender'] = 1;
         unset($extra[$index]);
     }
     if (is_array($url) && !isset($extra['url'])) {
         $extra['url'] = array();
     }
     $extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
     $data = isset($extra['data']) ? $extra['data'] : null;
     unset($extra['data']);
     if (is_string($url)) {
         $request = new CakeRequest($url);
     } elseif (is_array($url)) {
         $params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
         $params = array_merge($params, $extra);
         $request = new CakeRequest(Router::reverse($params), false);
     }
     if (isset($data)) {
         $request->data = $data;
     }
     $dispatcher = new Dispatcher();
     $result = $dispatcher->dispatch($request, new CakeResponse(), $extra);
     Router::popRequest();
     return $result;
 }
Example #2
Show file File: Object.php Project: julkar9/gss
0
 /**
  * Calls a controller's method from any location.
  * Can be used to connect controllers together
  * or tie plugins into a main application. requestAction can be used to return rendered views
  * or fetch the return value from controller actions.
  *
  * Under the hood this method uses Router::reverse() to convert the $url parameter into a string
  * URL. You should use URL formats that are compatible with Router::reverse()
  *
  * #### Passing POST and GET data
  *
  * POST and GET data can be simulated in requestAction. Use `$extra['url']` for
  * GET data. The `$extra['data']` parameter allows POST data simulation.
  *
  * @param string|array $url
  *        	String or array-based url. Unlike other url arrays in CakePHP, this
  *        	url will not automatically handle passed and named 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 named/passed arguments.
  * @return mixed Boolean true or false on success/failure, or contents
  *         of rendered action if 'return' is set in $extra.
  */
 public function requestAction($url, $extra = array())
 {
     if (empty($url)) {
         return false;
     }
     App::uses('Dispatcher', 'Routing');
     if (($index = array_search('return', $extra)) !== false) {
         $extra['return'] = 0;
         $extra['autoRender'] = 1;
         unset($extra[$index]);
     }
     if (is_array($url) && !isset($extra['url'])) {
         $extra['url'] = array();
     }
     $extra = array_merge(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
     $data = isset($extra['data']) ? $extra['data'] : null;
     unset($extra['data']);
     if (is_string($url) && strpos($url, FULL_BASE_URL) === 0) {
         $url = Router::normalize(str_replace(FULL_BASE_URL, '', $url));
     }
     if (is_string($url)) {
         $request = new CakeRequest($url);
     } elseif (is_array($url)) {
         $params = $url + array('pass' => array(), 'named' => array(), 'base' => false);
         $params = array_merge($params, $extra);
         $request = new CakeRequest(Router::reverse($params), false);
     }
     if (isset($data)) {
         $request->data = $data;
     }
     $dispatcher = new Dispatcher();
     $result = $dispatcher->dispatch($request, new CakeResponse(), $extra);
     Router::popRequest();
     return $result;
 }
Example #3
Show file File: CakeRequestTest.php Project: mgoo/MovieServer
0
 /**
  * Tests that overriding the method to GET will clean all request
  * data, to better simulate a GET request.
  *
  * @return void
  */
 public function testMethodOverrideEmptyData()
 {
     $_POST = array('_method' => 'GET', 'foo' => 'bar');
     $_SERVER['REQUEST_METHOD'] = 'PUT';
     $request = new CakeRequest('/posts/edit/1');
     $this->assertEmpty($request->data);
     $_POST = array('foo' => 'bar');
     $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'GET';
     $request = new CakeRequest('/posts/edit/1');
     $this->assertEmpty($request->data);
 }
Example #4
Show file File: CakeRequestTest.php Project: julkar9/gss
0
 /**
  * Test is('requested') and isRequested()
  *
  * @return void
  */
 public function testIsRequested()
 {
     $request = new CakeRequest('/posts/index');
     $request->addParams(array('controller' => 'posts', 'action' => 'index', 'plugin' => null, 'requested' => 1));
     $this->assertTrue($request->is('requested'));
     $this->assertTrue($request->isRequested());
     $request = new CakeRequest('/posts/index');
     $request->addParams(array('controller' => 'posts', 'action' => 'index', 'plugin' => null));
     $this->assertFalse($request->is('requested'));
     $this->assertFalse($request->isRequested());
 }
Example #5
Show file File: DispatcherTest.php Project: Oswald-Dsa/cakephp-ex
0
 /**
  * testHttpMethodOverrides method
  *
  * @return void
  */
 public function testHttpMethodOverrides()
 {
     Router::reload();
     Router::mapResources('Posts');
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $dispatcher = new Dispatcher();
     $request = new CakeRequest('/posts');
     $event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'] = 'PUT';
     $request = new CakeRequest('/posts/5');
     $event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     unset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $request = new CakeRequest('/posts/5');
     $event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'view', '[method]' => 'GET');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     $_POST['_method'] = 'PUT';
     $request = new CakeRequest('/posts/5');
     $event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array('5'), 'named' => array(), 'id' => '5', 'plugin' => null, 'controller' => 'posts', 'action' => 'edit', '[method]' => 'PUT');
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     $_POST['_method'] = 'POST';
     $_POST['data'] = array('Post' => array('title' => 'New Post'));
     $_POST['extra'] = 'data';
     $_SERVER = array();
     $request = new CakeRequest('/posts');
     $event = new CakeEvent('DispatcherTest', $dispatcher, array('request' => $request));
     $dispatcher->parseParams($event);
     $expected = array('pass' => array(), 'named' => array(), 'plugin' => null, 'controller' => 'posts', 'action' => 'add', '[method]' => 'POST', 'data' => array('extra' => 'data', 'Post' => array('title' => 'New Post')));
     foreach ($expected as $key => $value) {
         $this->assertEquals($value, $request[$key], 'Value mismatch for ' . $key . ' %s');
     }
     unset($_POST['_method']);
 }
Frequently Used Methods