Reputation: 345
I have an Array $testes that recieves two arrays $variavel1 and $variavel2. Then I set:
$this->set('testes', $testes)
In View How I can Take the values from $variavel1
and $variavel2
?
I tried $testes['$variavel1']['field']
, but I got Undefined Index $variavel1
Practical Example:
Array ( [0] => Array ( [ProcuraProdutoPedOnline] => Array ( [cd_familia] => 3 [ds_familia] => ACESSORIOS ) ) [1] => Array ( [ProcuraProdutoPedOnline] => Array ( [cd_familia] => 1 [ds_familia] => CALCADOS ) )
and
Array ( [0] => Array ( [VwEstPedOnline] => Array ( [cd_seq_pedido] => 2034 ) ) [1] => Array ( [VwEstPedOnline] => Array ( [cd_seq_pedido] => 2038 ) )
And i'm setting $testes
like this, $testes = array($variavel1, $variavel2);
Images to explain my problem:
Upvotes: 2
Views: 71
Reputation: 941
I think you first need to know the array structure. Add this to your view and you'll get a list:
echo '<pre>';
print_r($testes);
echo '</pre>';
If the result is empty the problem might be in the place where you add $variavel1 and $variavel2 to the variable $testes...
EDIT 2: By your example Array:
// Result should be 2034
echo $testes['0']['0']['VwEstPedOnline']['cd_seq_pedido'];
EDIT 3 as answer to your question in the comments to this post:
I still don't understand how $variavel1 and $variavel2 are associated. If there is no connection, you don't need to merge them into one array. You can simply use one foreach within another foreach:
In your controller:
$familias = $this->ProcuraProdutoPedOnline->find('all', array(
'fields' => array('cd_familia', 'ds_familia'),
'order' => 'cd_familia'));
$this->set('familias', $familias);
$cdSeqPeds = $this->VwEstPedOnline->find('all', array(
'fields' => 'cd_seq_pedido',
'order' => 'cd_seq_pedido'));
$this->set('cdSeqPeds', $cdSeqPeds);
And in your view:
foreach ( $familias as $var1 ) {
echo '<p>'.$var1['ProcuraProdutoPedOnline']['ds_familia'].':</p>';
echo '<ul>';
foreach ( $cdSeqPeds as $var2 ) {
echo '<li>'.$var2['VwEstPedOnline']['cd_seq_pedido'].'</li>';
}
echo '</ul>';
}
The result shoul be something like this:
ACESSORIOS:
· 2034
· 2038
CALCADOS:
· 2034
· 2038
If this doesn't answer your question, please make an example (with english variable names) what you want to get exactly and how the two tables are connected/associated...
Upvotes: 3