Skip to content

Commit

Permalink
fix urlRule classes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrtechno committed Aug 14, 2021
1 parent 9970a0a commit 54e3e91
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 25 deletions.
18 changes: 11 additions & 7 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use panix\engine\WebModule;
use yii\base\BootstrapInterface;
use app\web\themes\dashboard\sidebar\BackendNav;
use yii\web\UrlNormalizer;

class Module extends WebModule implements BootstrapInterface
{
Expand Down Expand Up @@ -170,21 +171,24 @@ public function bootstrap($app)


}
$rules[] = [
'class' => 'panix\mod\shop\components\BaseTest2UrlRule',
'route' => 'shop/catalog/sales',
'index' => 'sales',
'pattern' => 'sales',
];



$rules[] = [
'class' => 'panix\mod\shop\components\BaseTest2UrlRule',
'route' => '/shop/catalog/new',
'route' => 'shop/catalog/new',
'index' => 'new',
'pattern' => 'new'
];

/////////////////////////////////////////////
$rules[] = [
'class' => 'panix\mod\shop\components\BaseTest2UrlRule',
'route' => '/shop/catalog/sales',
'index' => 'sales',
'pattern' => 'sales'
];

/*$rules[] = [
'class' => 'app\engine\BaseUrlRule',
'route' => 'shop/catalog/best',
Expand Down
7 changes: 3 additions & 4 deletions README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ php yii migrate --migrationPath=vendor/panix/mod-shop/migrations
- /new

| catalog | sales | new |
|----------|:-------------:|------:|
| col 1 is | `$categories` | $1600 |
| col 2 is | centered | $12 |
| col 3 is | right-aligned | $1 |
|-----------|:-------------:|------:|
| --- |`$categories`| --- |
| --- | --- | --- |


### Автор и лицензия
Expand Down
40 changes: 30 additions & 10 deletions components/BaseTest2UrlRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function createUrl($manager, $route, $params)
{
if ($route === $this->route) {
if (isset($params['slug'])) {
$url = trim($params['slug'], '/');
$url = '/'.trim($params['slug'], '/');
unset($params['slug']);
} else {
$url = '';
Expand All @@ -38,6 +38,7 @@ public function createUrl($manager, $route, $params)
}
$url .= '/' . implode('/', $parts);
}

return $this->index . $url . $this->suffix;
}
return false;
Expand All @@ -47,17 +48,36 @@ public function createUrl($manager, $route, $params)
public function parseRequest($manager, $request)
{

$params = [];
$pathInfo = $request->getPathInfo();

$basePathInfo = $pathInfo;
if (empty($pathInfo))
//original begin
if ($this->mode === self::CREATION_ONLY) {
return false;
}

if ($this->suffix)
$pathInfo = strtr($pathInfo, [$this->suffix => '']);
if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
return false;
}

$suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
$pathInfo = $request->getPathInfo();
$normalized = false;
if ($this->hasNormalizer($manager)) {
$pathInfo = $this->getNormalizer($manager)->normalizePathInfo($pathInfo, $suffix, $normalized);
}
if ($suffix !== '' && $pathInfo !== '') {
$n = strlen($suffix);
if (substr_compare($pathInfo, $suffix, -$n, $n) === 0) {
$pathInfo = substr($pathInfo, 0, -$n);
if ($pathInfo === '') {
// suffix alone is not allowed
return false;
}
} else {
return false;
}
}
//original end

$params=[];
$pathInfoParse = str_replace($this->index . '/', '', $pathInfo);
$parts = explode('/', $pathInfoParse);
if ($this->index == mb_substr($pathInfo, 0,strlen($this->index))) {
Expand All @@ -78,8 +98,8 @@ public function parseRequest($manager, $request)
return false;
}*/

// CMS::dump([$this->route, $params]);
// die;
// CMS::dump([$this->route, $params]);
//die;
return [$this->route, $params];
}
return false;
Expand Down
5 changes: 3 additions & 2 deletions components/CategoryUrlRuleNew.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ public function createUrl($manager, $route, $params)

if ($route === $this->route) {
if (isset($params['slug'])) {
$url = trim($params['slug'], '/');
$url = '/'.trim($params['slug'], '/');
unset($params['slug']);
} else {
$url = '';
}
//echo $url;die;
$parts = [];
if (!empty($params)) {
foreach ($params as $key => $val) {
Expand All @@ -110,7 +111,7 @@ public function createUrl($manager, $route, $params)
$url .= '/' . implode('/', $parts);
}

return $this->index.'/' . $url . $this->suffix;
return $this->index . $url . $this->suffix;
// return $url . $this->suffix;
}
return parent::createUrl($manager, $route, $params);
Expand Down
1 change: 1 addition & 0 deletions components/FilterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class FilterController extends WebController
public $_maxPrice, $_minPrice;

public $currentUrl;
public $refreshUrl;
public $itemView = '_view_grid';
public $per_page;
public $filter;
Expand Down
5 changes: 4 additions & 1 deletion controllers/CatalogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function actionView()
$this->pageName = $this->dataModel->name;
$this->view->setModel($this->dataModel);
//$this->view->title = $this->pageName;
$this->refreshUrl= $this->dataModel->getUrl();
$this->view->registerJs("var current_url = '" . Url::to($this->dataModel->getUrl()) . "';", yii\web\View::POS_HEAD, 'current_url');


Expand Down Expand Up @@ -382,7 +383,7 @@ public function actionSales()
$this->query->applyCategories(array_unique($categories), 'orWhere');
}

$this->currentUrl = Url::to(['sales']);
$this->currentUrl = Url::to(['/shop/catalog/sales']);

$this->pageName = Yii::t('shop/default', 'DISCOUNT');
$categoriesIds=[];
Expand All @@ -396,6 +397,7 @@ public function actionSales()
$category = $this->findModel(Yii::$app->request->getQueryParam('slug'));
$this->query->applyCategories($category);
$this->currentUrl = Url::to($category->getUrl('sales'));

$this->view->params['breadcrumbs'][] = [
'url'=>['/shop/catalog/sales'],
'label'=>$this->pageName
Expand All @@ -404,6 +406,7 @@ public function actionSales()
$this->pageName = $category->name;

}
$this->refreshUrl= $this->currentUrl;
$this->view->params['breadcrumbs'][] = $this->pageName;


Expand Down
3 changes: 2 additions & 1 deletion widgets/filtersnew2/views/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<?php
echo Html::beginTag('div', ['id' => 'ajax_filter_current']);
if (!empty($active)) {
$url = ($this->model) ? $this->model->getUrl() : ['/' . Yii::$app->requestedRoute];
// echo Yii::$app->controller->refreshUrl;
$url = Yii::$app->controller->refreshUrl;
echo $this->render(Yii::$app->getModule('shop')->filterViewCurrent, ['active' => $active, 'dataModel' => $this->context->model, 'url' => $url]);
}
echo Html::endTag('div');
Expand Down

0 comments on commit 54e3e91

Please sign in to comment.