本文整理汇总了PHP中common\models\Product::attributeLabels方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::attributeLabels方法的具体用法?PHP Product::attributeLabels怎么用?PHP Product::attributeLabels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common\models\Product
的用法示例。
在下文中一共展示了Product::attributeLabels方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionExport
/**
* batch export product
* @param integer $id
* @return mixed
*/
public function actionExport()
{
//if(!Yii::$app->user->can('viewYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
$format = Product::getImportExportFormat();
$products = Product::find()->orderBy(['id' => SORT_ASC])->all();
$str = '';
// 生成csv标题行
$product = new Product();
$start = true;
foreach ($format as $column) {
if ($start) {
$str .= '"' . iconv('utf-8', 'gb2312', $product->attributeLabels()[$column]) . '"';
$start = false;
} else {
$str .= ',"' . iconv('utf-8', 'gb2312', $product->attributeLabels()[$column]) . '"';
}
}
$str .= ',' . iconv('utf-8', 'gb2312', Yii::t('app', 'Thumbs')) . ',' . iconv('utf-8', 'gb2312', Yii::t('app', 'Images'));
$str .= "\n";
foreach ($products as $row) {
// 导出 product表中的数据
$start = true;
foreach ($format as $column) {
$value = '';
if ($column == 'category_id') {
if ($row[$column] > 0) {
$category = Category::findOne($row[$column]);
$value = iconv('utf-8', 'gb2312', $category->name);
}
} elseif ($column == 'brand_id') {
if ($row[$column] > 0) {
$brand = Brand::findOne($row[$column]);
$value = iconv('utf-8', 'gb2312', $brand->name);
}
} else {
$value = iconv('utf-8', 'gb2312', $row[$column]);
}
if ($start) {
$str .= '"' . $value . '"';
$start = false;
} else {
$str .= ',"' . str_replace("\"", "\"\"", $value) . '"';
}
}
// 导出product_image表中的数据
$start = true;
$strThumb = $strImage = '';
$productImages = ProductImage::find()->where(['product_id' => $row->id])->all();
foreach ($productImages as $item) {
if ($start) {
$strThumb .= $item->thumb;
$strImage .= $item->image;
$start = false;
} else {
$strThumb .= '|' . $item->thumb;
$strImage .= '|' . $item->image;
}
}
$str .= ',"' . $strThumb . '","' . $strImage . '"';
$str .= "\n";
}
$filename = date('Ymd') . '.csv';
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=" . $filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $str;
}