Я пытаюсь увеличить запись таблицы с моего контроллера, но это не удается, я хочу создать метод добавления в корзину, который будет вставлять новый продукт или обновлять количество существующего. Также мне хотелось бы узнать, есть ли какая-либо книга или учебник (кроме учебника с сайта cakephp), который подробно объясняет cakephp. Я новичок, чтобы делать трюк и кажется очень запутанным, любая помощь приветствуется и ценится.cakephp 3 increment record
Контроллер
Мой код:
> function add($id = null,$name = null){
>
> $addCart = $this->Cart->newEntity();
>
> if($this->request->is('Get')){
>
> $data1 = $this->Cart->exists(['productId' => $id]);
>
> //if product doesn't exist in table then add it
> if(!$data1){
> $addCart = $this->Cart->patchEntity($addCart,[
> 'productId' => $id,
> 'name' => $name,
> 'productQty' => 1]
> );
> if($this->Cart->save($addCart)){
> $this->Flash->success(__('The product has been saved.'));
> return $this->redirect(['controller' => 'users','action' => 'index']);
> }else{
> $this->Flash->error(__('The product could not be saved. Please, try again.'));
> }
>
> }else{ //if product already exists in table then update quantity
> $updateQty = $this->Cart->patchEntity($addCart, [
> ['productQty' => 'productQty+1'],
> 'conditions' => ['productId' => $id] //update quantity where the product id matches
> ]);
> if($this->Cart->save($updateQty)){
> $this->Flash->success(__('The product already exists.Quantity updated'));
> return $this->redirect(['controller' => 'users','action' => 'index']);
> }else{
> $this->Flash->error(__('The product could not be updated. Please, try again.'));
> }
> }//end inner if
>
> }//end if
> }//end function
VIEW
<button class="btn btn-default">
<?= $this->Html->link('Add Product',['controller' => 'Cart', 'action' => 'add',2,'gpu'])
//$this->Html->link('Add Product',['controller' => 'Cart', 'action' => 'index'])
?>
</button>
Ok спасибо. работает без $ query-> newExpr. set ([('productQty = productQty + 1')]) –