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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:49:38+00:00 2026-06-12T06:49:38+00:00

I’ve read the documentation for the Authentication core library , and it’s not really

  • 0

I’ve read the documentation for the Authentication core library
, and it’s not really clear how to use it. It seems to assume a lot of prior knowledge.

Specifically:

You configure authentication handlers using $this->Auth->authenticate.
You can configure one or many handlers for authentication. Using
multiple handlers allows you to support different ways of logging
users in. When logging users in, authentication handlers are checked
in the order they are declared. Once one handler is able to identify
the user, no other handlers will be checked. Conversely you can halt
all authentication by throwing an exception. You will need to catch
any thrown exceptions, and handle them as needed.

You can configure authentication handlers in your controller’s
beforeFilter or, in the $components array
. You can pass configuration
information into each authentication object, using an array:

So in my PeopleController I wrote in the example code:

<?php
class PeopleController extends AppController {
    public $helpers = array('Html', 'Form');

    $this->Auth->authenticate = array(
        AuthComponent::ALL => array('userModel' => 'Member'),
        'Form',
        'Basic'
    );

    public function index() {

    }
}

And this exception fires:

syntax error, unexpected ‘$this’ (T_VARIABLE), expecting function
(T_FUNCTION) Error: An Internal Error Has Occurred.

Stack Trace CORE\Cake\Error\ErrorHandler.php line 162 →
ErrorHandler::handleFatalError(integer, string, string, integer)
[internal function] → ErrorHandler::handleError(integer, string,
string, integer, array) CORE\Cake\Core\App.php line 926 →
call_user_func(string, integer, string, string, integer, array)
CORE\Cake\Core\App.php line 899 → App::_checkFatalError() [internal
function] → App::shutdown()

Can anybody provide a simple example of how to protect a Controller so only an authenticated user can access it? Can I also protect individual Action functions?

  • 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-12T06:49:40+00:00Added an answer on June 12, 2026 at 6:49 am

    If I’m not wrong you should do it in the beforeFilter()

    public function beforeFilter(){
        parent::beforeFilter();
        $this->Auth->authenticate = array(
            AuthComponent::ALL => array('userModel' => 'Member'),
            'Form',
            'Basic'
        );
    }
    

    And also, as Martin already mentioned, $this can be used only in an (object) method, as $this refers to the current object from which the method is called.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.