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 4540224
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:03:23+00:00 2026-05-21T15:03:23+00:00

I am new to CakePHP and MVC in general. I am trying to create

  • 0

I am new to CakePHP and MVC in general. I am trying to create a web application for my friends and family.

I would like to have a login form at the top of the page, and a listing of events in the body. I would like the events to be displayed even if the user is not logged in. When the user logins using the form at the top I would like the events listing to update with additional information that would not be displayed to a user who is not logged in.

I want similar functionality on other pages as well.

What I have done so far:
1) Create a layout that contains my header and footer.
2) Include in the layout a custom “Element” that is the login form.

Ideally what would happen is when you typed in your login information, the login “Element” would send a ajax request to validate the login. It would then update and say something like “Welcome User”. I would also like it to then send another ajax request to a update method of the current controller, whatever that may be. The current controller would than change what was displayed on the page, if anything was login dependent.

Is this a good design? Is it feasible which CakePHP. So far in searching it seems that “Elements” are meant to be self contained and having it call a function of the “current controller” seems odd.

Any help would be appreciated.

Thank you.

  • 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-05-21T15:03:24+00:00Added an answer on May 21, 2026 at 3:03 pm

    Yes, your design is feasible. Your controller actions always render a ‘view’. No, what you put into that view is up to you. It can be as little as an element.

    You will need to have the login form/button make a call to the login action and have it render the return as json. You’ll want to update the login function to handle responding to an ajax request. This can be annoying to set up so I’m going to provide some code.

    Be sure to include RequestHandler component and Js helper in your app controller.

    app/controllers/users_controller.php:

    function login() {
        if($this->RequestHandler->isAjax()) {
            ...
            $this->set('status', /*whatever data you want to send*/);
            // Explicit call to render an ajax response, using a layout and view made specifically for ajax
            $this->layout = 'json';
            $this->render('ajax_login');    
        }
        // render views/users/login.ctp like normal
    }
    

    Your app/views/layouts/json.ctp file:

    <?php
        header("Pragma: no-cache");
        header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
        header('Content-Type: text/x-json');
        header("X-JSON: ".$content_for_layout);
    
        echo $content_for_layout;
    ?>
    

    Your app/views/users/ajax_login.ctp file:

    <?php echo $js->object($status); ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Helo... i'm new in cakephp, i want to create 2 login form, 1 for
I'm using the new CakePHP 2.1 and would like to use the JsonView to
I'm new to cakePHP.I just tried to create a simple form with a text
I'm new to the MVC pattern but have been trying to grasp it, for
I am new to CakePHP. I would like to use the model validate mechanism,
Ok so I'm I'm fairly new to cakephp, and I have a search form
I am new to cakephp and I'm trying to accomplish something that should be
I'm new to cakephp and trying to write a simple app with it, however
I'm extremely new to CakePHP. From what I've gathered, it seems like I can
I'm new to cakephp so go easy on me! I have a table called

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.