lithium\data\model\Query::data PHP Method

data() public method

Set and get method for the query's record's data.
public data ( array $data = [] ) : array
$data array if set, will set given array.
return array Empty array if no data, array of data if the record has it.
    public function data($data = array())
    {
        $bind =& $this->_entity;
        if ($data) {
            $bind ? $bind->set($data) : ($this->_data = array_merge($this->_data, $data));
            return $this;
        }
        $data = $bind ? $bind->data() : $this->_data;
        return ($list = $this->_config['whitelist']) ? array_intersect_key($data, $list) : $data;
    }

Usage Example

Example #1
0
 /**
  * Tests that assigning a whitelist to a query properly restricts the list of data fields that
  * the query exposes.
  *
  * @return void
  */
 public function testWhitelisting()
 {
     $data = array('foo' => 1, 'bar' => 2, 'baz' => 3);
     $query = new Query(compact('data'));
     $this->assertEqual($data, $query->data());
     $query = new Query(compact('data') + array('whitelist' => array('foo', 'bar')));
     $this->assertEqual(array('foo' => 1, 'bar' => 2), $query->data());
 }