提交 af4566b6 编写于 作者: T Terry

category block

上级 278635f9
...@@ -199,13 +199,14 @@ class Index extends \yii\base\BaseObject ...@@ -199,13 +199,14 @@ class Index extends \yii\base\BaseObject
} }
} }
$frontSort = []; $frontSort = [];
$hasSelect = false;
if (is_array($sort) && !empty($sort)) { if (is_array($sort) && !empty($sort)) {
$attrUrlStr = $this->_sort; $attrUrlStr = $this->_sort;
$dirUrlStr = $this->_direction; $dirUrlStr = $this->_direction;
foreach ($sort as $np=>$info) { foreach ($sort as $np=>$info) {
$label = $info['label']; $label = $info['label'];
$direction = $info['direction']; $direction = $info['direction'];
$arr['sort'] = [ $arr['sort']= [
'key' => $attrUrlStr, 'key' => $attrUrlStr,
'val' => $np, 'val' => $np,
]; ];
...@@ -214,19 +215,23 @@ class Index extends \yii\base\BaseObject ...@@ -214,19 +215,23 @@ class Index extends \yii\base\BaseObject
'val' => $direction, 'val' => $direction,
]; ];
$urlInfo = Yii::$service->url->category->getFilterSortAttrUrl($arr, $this->_page); $urlInfo = Yii::$service->url->category->getFilterSortAttrUrl($arr, $this->_page);
//var_dump($urlInfo); if ($urlInfo['selected']) {
//exit; $hasSelect = true;
}
$frontSort[] = [ $frontSort[] = [
'label' => $label, 'label' => $label,
'value' => $np, 'value' => $np,
'url' => $urlInfo['url'], 'url' => $urlInfo['url'],
'selected' => $urlInfo['selected'], 'selected' => $urlInfo['selected'],
]; ];
} }
} }
if (!$hasSelect ){ // 默认第一个为选中的排序方式
$frontSort[0]['selected'] = true;
}
$data = [ $data = [
'frontNumPerPage' => $frontNumPerPage, 'frontNumPerPage' => $frontNumPerPage,
'frontSort' => $frontSort, 'frontSort' => $frontSort,
]; ];
return $data; return $data;
......
...@@ -213,6 +213,7 @@ class Index extends \yii\base\BaseObject ...@@ -213,6 +213,7 @@ class Index extends \yii\base\BaseObject
} }
} }
$frontSort = []; $frontSort = [];
$hasSelect = false;
if (is_array($sort) && !empty($sort)) { if (is_array($sort) && !empty($sort)) {
$attrUrlStr = $this->_sort; $attrUrlStr = $this->_sort;
$dirUrlStr = $this->_direction; $dirUrlStr = $this->_direction;
...@@ -228,7 +229,9 @@ class Index extends \yii\base\BaseObject ...@@ -228,7 +229,9 @@ class Index extends \yii\base\BaseObject
'val' => $direction, 'val' => $direction,
]; ];
$urlInfo = Yii::$service->url->category->getFilterSortAttrUrl($arr, $this->_page); $urlInfo = Yii::$service->url->category->getFilterSortAttrUrl($arr, $this->_page);
if ($urlInfo['selected']) {
$hasSelect = true;
}
$frontSort[] = [ $frontSort[] = [
'label' => $label, 'label' => $label,
'value' => $np, 'value' => $np,
...@@ -237,6 +240,9 @@ class Index extends \yii\base\BaseObject ...@@ -237,6 +240,9 @@ class Index extends \yii\base\BaseObject
]; ];
} }
} }
if (!$hasSelect ){ // 默认第一个为选中的排序方式
$frontSort[0]['selected'] = true;
}
$data = [ $data = [
'frontNumPerPage' => $frontNumPerPage, 'frontNumPerPage' => $frontNumPerPage,
'frontSort' => $frontSort, 'frontSort' => $frontSort,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册