FavoriteService::remove PHP Метод

remove() публичный Метод

public remove ( $productId ) : boolean
$productId
Результат boolean
    public function remove($productId)
    {
        $products = $this->getData();
        if (isset($products[$productId])) {
            unset($products[$productId]);
            Yii::app()->eventManager->fire(FavoriteEvents::REMOVE_FROM_FAVORITE, new FavoriteServiceEvent($productId, $this->session));
            return $this->setData($products);
        }
        return false;
    }

Usage Example

Пример #1
0
 /**
  * @throws CHttpException
  */
 public function actionRemove()
 {
     if (!Yii::app()->getRequest()->getIsPostRequest() || !Yii::app()->getRequest()->getIsAjaxRequest()) {
         throw new CHttpException(404);
     }
     $productId = (int) Yii::app()->getRequest()->getPost('id');
     if (!$productId) {
         throw new CHttpException(404);
     }
     if ($this->favorite->remove($productId)) {
         Yii::app()->ajax->raw(['result' => true, 'data' => Yii::t('FavoriteModule.favorite', 'Success removed!'), 'count' => $this->favorite->count()]);
     }
     Yii::app()->ajax->raw(['message' => Yii::t('FavoriteModule.favorite', 'Error =('), 'result' => false, 'count' => $this->favorite->count()]);
 }