/** * get the name from product by string * */ public function actionName() { $params = $this->getQuery(); if (empty($params['id'])) { throw new BadRequestHttpException('missing params'); } $accountId = $this->getAccountId(); $condition['id'] = []; $ids = explode(',', $params['id']); foreach ($ids as $key => $id) { $condition['id'][] = new MongoId($id); } $products = Product::getProductsName($condition, $accountId); return array_map(function ($product) { return $product->name; }, $products); }