Reputation: 3535
I'm developing an API for Cakephp where I pass some query parameters from a controller to another. These query must be arbitrary and could be related to several different models but the interesting result is always an integer.
The problem is that CakePHP always return an array with a different structure and keys for this array are always different.
How can I access the value I need or simplify the query to return a simple value?
Upvotes: 0
Views: 126
Reputation: 1540
I think you should look at Set::extract and rewrite the name of your fields in an unified way
<?
$res = $this->Model->query('select Model.myfield as myint from mytable Model');
$res = Set::extract( "/Model/myint", $res );
// $res = array( 0 => "value 1", ...);
see http://book.cakephp.org/view/1501/extract or play a bit with array_shift to extract the first value in a loop.
hope this help. L
Upvotes: 1