Basket::find PHP Method

find() public method

Return items that match key/value pair; If no key/value pair specified, return all items
public find ( $key = NULL, $val = NULL ) : array
$key string
$val mixed
return array
    function find($key = NULL, $val = NULL)
    {
        $out = [];
        if (isset($_SESSION[$this->key])) {
            foreach ($_SESSION[$this->key] as $id => $item) {
                if (!isset($key) || array_key_exists($key, $item) && $item[$key] == $val) {
                    $obj = clone $this;
                    $obj->id = $id;
                    $obj->item = $item;
                    $out[] = $obj;
                }
            }
        }
        return $out;
    }

Usage Example

 /**
  * testFindAllWithConditionInChildQuery
  *
  * @return void
  */
 public function testFindAllWithConditionInChildQuery()
 {
     $this->loadFixtures('Basket', 'FilmFile');
     $TestModel = new Basket();
     $recursive = 3;
     $result = $TestModel->find('all', compact('recursive'));
     $expected = array(array('Basket' => array('id' => 1, 'type' => 'nonfile', 'name' => 'basket1', 'object_id' => 1, 'user_id' => 1), 'FilmFile' => array('id' => '', 'name' => '')), array('Basket' => array('id' => 2, 'type' => 'file', 'name' => 'basket2', 'object_id' => 2, 'user_id' => 1), 'FilmFile' => array('id' => 2, 'name' => 'two')));
     $this->assertEquals($expected, $result);
 }
All Usage Examples Of Basket::find