所以我想要做的是,在我的主要布局中,有一个登录用户的菜单,以及一个不同的匿名用户.
布局将在每个页面上使用,所以我不知道如何做到这一点,正如我所见,Auth组件只能在控制器中使用,如果我只需要在一个控件中执行此操作,这将是很好的查看,但对于每个视图,我该怎么做?我必须在AppController上做点什么吗?
我想做的基本上是
// layout <?php if(logged): ?> Welcome <?php echo $user; ?> <?php else: ?> Welcom anon,Log in? <?php endif; ?>
您也可以使用Auth组件访问视图中的登录用户.从
manual:
Once a user is logged in,you will often need some particular
information about the current user. You can access the currently
logged in user using AuthComponent::user(). This method is static,and
can be used globally after the AuthComponent has been loaded. You can
access it both as an instance method or as a static method:
// Use anywhere AuthComponent::user('id') // From inside a controller $this->Auth->user('id');
你应该可以这样做:
// layout <?php if(AuthComponent::user('name')): ?> Welcome <?php echo AuthComponent::user('name'); ?> <?php else: ?> Welcom anon,Log in? <?php endif; ?>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。