Recover data simplified
How to retrieve data in the form ID => Label
It happens to want to retrieve data in the form of an associative array Id => Label
It is by practical example in the case of list of values used in the select.
$rows = $this->collector['example']->get(array('is_valid' => 1));
<span><br /><br />Array
(
[0] =<span class="entity"></span> Array
(
[id_example] =<span class="entity"></span> One
[lib] =<span class="entity"></span> Item 1
[created_at] =<span class="entity"></span> 2019-05-03 14:33:10
[n_order] =<span class="entity"></span> One
[is_valid] =<span class="entity"></span> One
[ex_type] =<span class="entity"></span> EX1
)
[1] =<span class="entity"></span> Array
(
[id_example] =<span class="entity"></span> Three
[lib] =<span class="entity"></span> Item 3
[created_at] =<span class="entity"></span> 2019-05-03 14:33:21
[n_order] =<span class="entity"></span> Three
[is_valid] =<span class="entity"></span> One
[ex_type] =<span class="entity"></span> EX2
)
)</span>
The method getKv (for getKeyValue) returns a key identifying the row value and the column that is used as follows :
<span>$rows = $this->collector['example']->getKv(array('is_valid' => 1));</span>
<span>Array
(
[1] =<span class="entity"></span> Item 1<br />
[3] =<span class="entity"></span> Item 3<br />
<span id="line121" span="">)</span></span>
The default behavior is to retrieve the column "lib".
However, some of the tables do not use this column name to represent the label of a given.
It is then possible to define in the class representing the collector field to use :
protected $_libField = 'ANOTHER FIELD'; <br /><br />
There is also the method getKandMore that is going to have the same operation as getKv, but with the possibility to add additional values, as in the example below :
<span>function getKandMore($fields=array(),$conditions = array(), $order = ", $limit = ") { }<br />
$rows = $this->collector['example']->getKandMore(array('lib','created_at'), array('is_valid'=>1));<br /></span>
Array
(
[1] = Item 1 2019-05-03 14:33:10
[3] = Item 3 2019-05-03 14:33:21
)