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

  • Home
  • SEARCH
  • 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 9178257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:30:35+00:00 2026-06-17T17:30:35+00:00

i have built upon this tutorial http://www.jamesfairhurst.co.uk/posts/view/creating_an_admin_section_with_cakephp_updated and currently have a functional and quite

  • 0

i have built upon this tutorial http://www.jamesfairhurst.co.uk/posts/view/creating_an_admin_section_with_cakephp_updated

and currently have a functional and quite well fleshed out admin section for my application.

Due to poor foresight I haven’t taken into account regular users who need to be able to login to their own home page, where they can view bookings etc.

I have an appropriate database set up and have included a ‘roles’ field for authentication. I have also followed cakePHP’s own ‘auth’ examples however have failed to get them to implement without throwing various errors, at this stage i’m not wanting to go changing the structure of the login system too much, that kind of thing can become a headache quick!!

I have spoken to the original author of the tutorial and he agrees that some simple logic added to the user_controller.php file should suffice.

basically i need something along the lines of an: “if user == ‘user’ THEN redirect to ‘user_index.php’ put simply.
below is the current LOGIN function for user_controller.php

function login() {
        if(!empty($this->data)) {
            // unset unrequired validation rules
            unset($this->User->validate['username']['check_username_exists']);

            // validate form
            $this->User->set($this->data);
            if($this->User->validates()) {
                // update Last Login date
                $this->User->id = $this->User->_user['User']['id'];
                $this->User->saveField('last_login',date("Y-m-d H:i:s"));

                // save User to Session and redirect
                $this->Session->write('User', $this->User->_user);
                $this->Session->setFlash('You have successfully logged in.','default',array('class'=>'flash_good'));
                $this->redirect(array('action'=>'index','admin'=>TRUE));
            }
        }
    }

All validation is handled in the user.php model and there is some logic in app_controller.php to redirect authentication, it is included below;

app_controller.php

class AppController extends Controller {
    // class variables
    var $_User = array();


    /**
     * Before any Controller action
     */
    function beforeFilter() {
        // if admin url requested
        if(isset($this->params['admin']) && $this->params['admin']) {
            // check user is logged in
            if( !$this->Session->check('User') ) {
                $this->Session->setFlash('You must be logged in for that action.','flash_bad');
                $this->redirect('/login');
            }

            // save user data
            $this->_User = $this->Session->read('User');
            $this->set('user',$this->_User);

            // change layout
            $this->layout = 'admin';
        }
    }
}
  • 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-17T17:30:36+00:00Added an answer on June 17, 2026 at 5:30 pm

    I faced a similar problem in my application. In my User model, I created a getRole() method which just pulled the role out of the database, and then I used a switch statement to redirect users to the correct controller.

    As a different approach, you could just add in an isAdmin column (default 0, 1 would indicate an admin) to your users table. Assuming there are not too many admins already, you could just manually set the admins. In your controller you would just need to check the field and the redirect accordingly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Windows service built upon ATL 7's CAtlServiceModuleT class. This service serves
I have seen the railscast on self-referential relationships here: http://railscasts.com/episodes/163-self-referential-association I have built upon
I have a wizard in my asp.net MVC application which is built upon this
http://www.sitepoint.com/build-to-do-list-30-minutes/ So I was doing this (http://www.sitepoint.com/build-to-do-list-30-minutes/) tutorial and everyting went OK. but now
In my company, we have a project built upon this pattern. I would like
I have built a game in HTML5 and a web form posts data to
I have a cube built in SSAS2008 that is built upon 2 tables -
I have a Website, which is built upon a CMS, written in PHP. And
I have an entire website built upon a link scheme of query strings (i.e.
I have some existing projects that were built upon a deprecated PHP framework, and

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.