data() public method

## Reading values. $request->data('Post.title'); When reading values you will get null for keys/values that do not exist. ## Writing values $request->data('Post.title', 'New post!'); You can write to any value, even paths/keys that do not exist, and the arrays will be created for you.
public data ( string $name ) : mixed | self
$name string Dot separated name of the value to read/write, one or more args.
return mixed | self Either the value being read, or $this so you can chain consecutive writes.
Ejemplo n.º 1
0
/**
 * Checks the fields to ensure they are supplied.
 *
 * @param CakeRequest $request The request that contains login information.
 * @param string $model The model used for login verification.
 * @param array $fields The fields to be checked.
 * @return boolean False if the fields have not been supplied. True if they exist.
 */
	protected function _checkFields(CakeRequest $request, $model, $fields) {
		if (empty($request->data[$model])) {
			return false;
		}
		foreach (array($fields['username'], $fields['password']) as $field) {
			$value = $request->data($model . '.' . $field);
			if (empty($value) || !is_string($value)) {
				return false;
			}
		}
		return true;
	}
Ejemplo n.º 2
0
 public function authenticate(CakeRequest $request, CakeResponse $response)
 {
     $params = json_decode($request->query('params'), true);
     if (!isset($params['username'])) {
         $params = json_decode($request->data('params'), true);
     }
     $options = array('conditions' => array('User.username' . $this->userController->User->username => $params['username']));
     $result = $this->userController->User->find('first', $options);
     if ($result) {
         $password = sha1($result['User']['username'] . $result['User']['password']);
         if ("Promobot" . $password == $params['auth']) {
             return $result['User'];
         }
     }
     return false;
 }
 /**
  * Test writing falsey values.
  *
  * @return void
  */
 public function testDataWritingFalsey()
 {
     $request = new CakeRequest('posts/index');
     $request->data('Post.null', null);
     $this->assertNull($request->data['Post']['null']);
     $request->data('Post.false', false);
     $this->assertFalse($request->data['Post']['false']);
     $request->data('Post.zero', 0);
     $this->assertSame(0, $request->data['Post']['zero']);
     $request->data('Post.empty', '');
     $this->assertSame('', $request->data['Post']['empty']);
 }
 /**
  * Checks the fields to ensure they are supplied.
  *
  * @param CakeRequest $request The request that contains login information.
  * @param string $model The model used for login verification.
  * @return bool False if the fields have not been supplied. True if they exist.
  */
 protected function checkFields(CakeRequest $request, $model)
 {
     if (empty($request->data[$model])) {
         return false;
     }
     foreach (array($this->settings['fields']['username'], $this->settings['fields']['password']) as $field) {
         $value = $request->data($model . '.' . $field);
         if (empty($value) && $value !== '0' || !is_string($value)) {
             return false;
         }
     }
     return true;
 }
 private static function setConditionContent(stdClass $std, CakeRequest $request)
 {
     $paginateOrmName = self::PAGINATE_ORM_NAME;
     $value = $request->data(['CategoriesSearch']);
     if (!empty($value['content'])) {
         $fieldName = $paginateOrmName . '.content Like';
         $std->conditions[0]['or'][$fieldName] = '%' . $value['content'] . '%';
     }
 }