抱着大树看星星
- 抱着大树看星星 回答了问题 update更新数据库问题
Yii2里可以使用model函数:updateAllCounters,如:
User::updateAllCounters(['total'=>5], ['status'=>1])
翻译为sql语句大概就是:UPDATE User SET total=total+5 WHERE status=1
- 抱着大树看星星 赞了评论
官方最新版本(2.6.0)已经解决了这个问题,可以达到子菜单级别的高亮:
` /*** Checks whether a menu item is active. * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item. * When the `url` option of a menu item is specified in terms of an array, its first element is treated * as the route for the item and the rest of the elements are the associated parameters. * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item * be considered active. * @param array $item the menu item to be checked * @return boolean whether the menu item is active */ 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 = ltrim(Yii::$app->controller->module->getUniqueId() . '/' . $route, '/'); } $route = ltrim($route, '/'); if ($route != $this->route && $route !== $this->noDefaultRoute && $route !== $this->noDefaultAction) { 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; } } } return true; } return false; }`
官方最新版本(2.6.0)已经解决了这个问题,可以达到子菜单级别的高亮:
` /*** Checks whether a menu item is active. * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item. * When the `url` option of a menu item is specified in terms of an array, its first element is treated * as the route for the item and the rest of the elements are the associated parameters. * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item * be considered active. * @param array $item the menu item to be checked * @return boolean whether the menu item is active */ 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 = ltrim(Yii::$app->controller->module->getUniqueId() . '/' . $route, '/'); } $route = ltrim($route, '/'); if ($route != $this->route && $route !== $this->noDefaultRoute && $route !== $this->noDefaultAction) { 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; } } } return true; } return false; }`