Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The corresponding button method is not displayed when yii2 does not have permission.

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "yii2 does not show the corresponding button method when there is no permission". In the daily operation, I believe that many people do not show the corresponding button when yii2 does not have permission. The editor consulted all kinds of materials and sorted out a simple and easy-to-use operation method. I hope it will be helpful for everyone to answer the doubt that "yii2 does not show the corresponding button method when there is no authority". Next, please follow the editor to study!

The main solution is that when we do not give the user a role, the corresponding button is not displayed, rather than commenting the code directly in the view.

1: you need to add the following code directly to the Html::a method

Public static function a ($text, $url = null, $options = []) {if ($url! = = null) {$options ['href'] = Url::to ($url); if (strstr ($options [' href'],'?)) {$newurl = substr ($options ['href'], 0if strrpos ($options [' href'],'?')) } else {$newurl = $options ['href'];} if (!\ Yii::$app- > user- > can ($newurl)) {return false;}} return static::tag (' text, $options) } at this point, the study on "yii2 does not show the corresponding button method when there is no permission" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report