CakeRequest::data PHP Method

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.
    public function data($name)
    {
        $args = func_get_args();
        if (count($args) === 2) {
            $this->data = Hash::insert($this->data, $name, $args[1]);
            return $this;
        }
        return Hash::get($this->data, $name);
    }

Usage Example

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;
	}
All Usage Examples Of CakeRequest::data