Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8549155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:39:39+00:00 2026-06-11T13:39:39+00:00

So what I want to do is, in my main layout, have a menu

  • 0

So what I want to do is, in my main layout, have a menu for logged in users, and a different for anon users.

THe layout will be used on every page, so I’m not sure how to do this, as I’ve seen, the Auth Component can only be used in the controller, this would be nice if I had to do this in only one view, but for every view, how can I do this? Do I have to do something on AppController?

What I want to do is basically

// layout
<?php if(logged): ?>
Welcome <?php echo $user; ?>
<?php else: ?>
Welcom anon, Log in?
<?php endif; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:39:40+00:00Added an answer on June 11, 2026 at 1:39 pm

    You can access the logged in user in your view using the Auth component as well. From the 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');
    

    You should be able to do something like:

    // layout
    <?php if(AuthComponent::user('name')): ?>
        Welcome <?php echo AuthComponent::user('name'); ?>
    <?php else: ?>
        Welcom anon, Log in?
    <?php endif; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do blog application and I want main page to have this
The background is : I have layout page main.gsp I need to conditionally show
I have a Main form.I want to launch another form from it and launch
I have a main.xml file describing the layout of my main activity: <?xml version=1.0
i have one main relative layout in that i have buttons and in middle
I have a class called Menu and inside that class I want to place
I want my main layout to conditionally put in some blocks of html that
I have this menu in _Layout.cshtml : <td class=MenuStructure> <ul id=menu> <li>@Html.ActionLink(First Page, Page1Action,
I have an application where the main layout is loaded from xml file. The
Here's the situation I'm trying to solve: I have a main shared layout with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.