Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suggest for yii\bootstrap\Nav #3678

Closed
510846 opened this issue Jun 3, 2014 · 1 comment
Closed

suggest for yii\bootstrap\Nav #3678

510846 opened this issue Jun 3, 2014 · 1 comment

Comments

@510846
Copy link

510846 commented Jun 3, 2014

Nav is a great Widget!

i want to improve function isItemActive(),
then can support "range page" property, you can use:

Nav::widget([
    'items' => ['label' => 'Product', 'url' => ['product/index'], 'rangepage' => [['product/view']]],
])

and the improved function isItemActive():

protected function isItemActive($item)
{
    if (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) {
        $route = $item['url'][0];
        if ($route[0] !== '/' && Yii::$app->controller) {
            $route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
        }

        if (!isset($item['rangepage'])) {
            if (ltrim($route, '/') !== $this->route) {
                return false;
            }
            unset($item['url']['#']);
            if (count($item['url']) > 1) {
                foreach (array_splice($item['url'], 1) as $name => $value) {
                    if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                        return false;
                    }
                }
            }
        } else {
            if (ltrim($route, '/') == $this->route) {
                unset($item['url']['#']);
                if (count($item['url']) > 1) {
                    $_m = true;
                    foreach (array_splice($item['url'], 1) as $name => $value) {
                        if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                            $_m = false;
                            break;
                        }
                    }
                    if ($_m) {
                        return true;
                    }
                } else {
                    return true;
                }
            }


            foreach ($item['rangepage'] as $rpitem) {
                $rproute = $rpitem[0];
                if ($rproute[0] !== '/' && Yii::$app->controller) {
                    $rproute = Yii::$app->controller->module->getUniqueId() . '/' . $rproute;
                }
                if (ltrim($rproute, '/') !== $this->route) {
                    continue;
                }

                $range_matched = true;
                foreach (array_splice($rpitem, 1) as $name => $value) {
                    if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                        $range_matched = false;
                        break;
                    }
                }
                if ($range_matched) {
                    return true;
                }
            }

            return false;
        }

        return true;
    }

    return false;
}
@yii-bot
Copy link

yii-bot commented Jan 24, 2016

Issue moved to yiisoft/yii2-bootstrap#102

@yii-bot yii-bot closed this as completed Jan 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants