Retrieve records by a field

How to proceed with the recovery of the records by the field ?

Each collector can call the magic method getBy or getOneBy or getKvBythat allows you to retrieve filtered data by field.


Settings

  1. The value sought.

Example

The following example allows you to retrieve the values of the collector "example" if the field "is_valid" is equal to 1.

$result = $this->collector['example']->getByIs_valid('1');

The function's return

This method returns an array containing the values.

Array 
( 
 [0] = Array 
 ( 
 [id_example] = One 
 [lib] = Item 1 
 [created_at] = 2019-05-03 14:33:10 
 [n_order] = One 
 [is_valid] = One 
 [ex_type] = EX1 
 ) 

 [1] = Array 
 ( 
 [id_example] = Three 
 [lib] = Item 3 
 [created_at] = 2019-05-03 14:33:21 
 [n_order] = Three 
 [is_valid] = One 
 [ex_type] = EX2 
 ) 

)

Method getOneBy

The method getOneBy works in the same way, the only difference is that the result returns only a single record.

$result = $this->collector['example']->getOneByLib('Item 3');

Method getKvBy

The method getKvBy works in the same way, the only difference is that the result returns the key and values (see method getKv()).

$result = $this->collector['example']->getKvByLib('Item 3')); 
Array ( [3] => Item 3)