Treat array in Cakephp 3 controller

Asked

Viewed 31 times

0

So people I have two controllers, sales and sales products, in which in the products sales I select product with checkbox and shipping by a buttom to another page, and in the product controller sales I would have to deal with the array, and it would be sent to sales to show on the screen the products I selected.

View of Productsrelations

<tbody>
    <?= $this->Form->create("carrinho", ["class " => "form-add", "action" => "carrinho", "controller" => "Produtos-Vendas"]) ?>
<button type="submit" class="btn-success btn">Carrinho (<span id="additem"></span>)</button>
<?php foreach ($produtos as $produto): ?>
    <tr>
        <td><?= $this->Number->format($produto->id) ?></td>
        <td><?= h($produto->name) ?></td>
        <td><?= h($produto->cor) ?></td>
        <td><?= h($produto->tecido) ?></td>
        <td><?= $this->Number->format($produto->estoque) ?></td>
        <td><?= $this->Number->format($produto->preco) ?></td>
        <td>
            <button type="button" class="btn-success btn addcart">+ Adicionar</button>
            <input type="checkbox" style="" name="check[]" class="checkbox" value="<?php echo $produto['id']; ?>">

        </td>
    </tr>   
<?php endforeach; ?>
<?= $this->Form->end() ?> 

Controller da Produtovendas

public function carrinho() {
    $check = $this->request->getData();
    if ($check == null) {
        return $this->redirect(['action' => 'index']);
    } else {
        return $this->redirect(['controller' => 'vendas', 'action' => 'index']);
    }
}

My problem is that I don’t know how to treat this $check array so that on the sales screen is displayed the one I selected

1 answer

0


I figured out how to solve my problem, my view remains the same, but in my controller it was like this:

    public function carrinho(){

    $check = $this->request->getData();
    if ($check == null) {
        return $this->redirect(['action' => 'index']);
    }else{
        session_start();
        $_SESSION['check'] = $check;  
        return $this->redirect(['controller' => 'vendas', 'action' => 'index']);
    }
}

And in the view that I would like to display/pass this data I just logged in to check again and extracted the values from Session.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.