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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T07:07:55+00:00 2026-06-07T07:07:55+00:00

This is a question more for opinions rather than for a solution to a

  • 0

This is a question more for opinions rather than for a solution to a specific problem.

I am working with CakePHP for the first time and am working on the admin part of the site now.

Where do you, as an MVC or CakePHP developer like to put your admin functions?

Initially I was putting them in an AdminController, but have since changed to putting the functions in a controller that is meant for the type of data being manipulated. For example, I put the user listings/editing in the UserController.

To me this makes more sense since there is likely to be functionality in the UserController that may be useful.

If you leave a response, could you please leave a few words saying why? Perhaps it is a moot point.

take care,
lee

— Edit

if ($this->Auth->user('user_type') == 1){//double-check the user is Admin
            $this->Auth->allow('display');
            $this->Auth->allow('watch');
  • 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-07T07:07:57+00:00Added an answer on June 7, 2026 at 7:07 am

    I don’t think it’s a moot point. Put the admin functions in their respective controllers (ie, not all together in one ‘admin’ controller), and use ‘admin’ prefix routing, built into Cake, to keep them secure. This is the CakePHP sanctioned way to do it, and CakePHP allows you to create admin functions in this way via the Bake console.

    You can protect all controller functions prefixed by admin_ with a few simple lines of code in your AppController, and all admin functions can be accessed via tidy, consistent URLs like this: http://www.example.com/admin/my_controller/my_function

    This should get you started: http://book.cakephp.org/2.0/en/development/routing.html#prefix-routing

    Let me know if you need more help and I’ll update my answer with more info.

    EDIT: More info…

    Here’s some steps to set up admin routing:

    1/ in app/Config/core.php, around line 113, make sure this line exists and is uncommented:

        Configure::write('Routing.prefixes', array('admin'));
    

    2/ In app/Controller/AppController.php (ie, the controller superclass), test for admin routing in your beforeFilter method. Do NOT do this in the beforeFilter of each controller – that is not in tune with DRY principles. Here’s my before filter method as an example:

    function beforeFilter() {
        if (isset($this->request->params['admin'])) {
                // the user has accessed an admin function, so handle it accordingly.
            $this->layout = 'admin';
            $this->Auth->loginRedirect = array('controller'=>'users','action'=>'index');
            $this->Auth->allow('login');
        } else {
                // the user has accessed a NON-admin function, so handle it accordingly.
            $this->Auth->allow();
    
        }
    }
    

    3/ Prefix all your admin functions with admin_ and they should automatically be available via prefix routing.

    eg.

    function admin_dostuff () { echo 'hi from the admin function'; } // This will be available via http://www.example.com/admin/my_controller/dostuff
    
    function dostuff () { echo 'hi from the NON-admin function'; } // This will be available via http://www.example.com/my_controller/dostuff
    

    Once you’ve got that set up, all you need to do is prefix admin functions with admin_, and Cake will handle it all for you. Make sense?

    EDIT 2:

    Here’s some quickly-written example code that should help your situation.

    function beforeFilter() {
        if (isset($this->request->params['admin'])) {
            // the user has accessed an admin_ function, so check if they are an admin.
            if ($this->Auth->user('user_type') == 1){
                // an Admin user has accessed an admin function. We can always allow that.
                $this->Auth->allow();
            } else {
                // A non-admin user has accessed an admin function, so we shouldn't allow it.
                // Here you can redirect them, or give an error message, or something
            }
        } else {
            // the user has accessed a NON-admin function, so handle it however you want.
            $this->Auth->allow(); // this example gives public access to all non-admin functions.
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is more about guidance than actually solving my problem: I need to
I suppose this question is more general than working with COM components. I have
First of all, this is a design question rather than an issue: I have
This question is more philosophical than technical. I've trained myself as a web developer
This question is more UI/Design-ish than hard-core programming is. Background: I've been coding in
This question is more a re-insurance than one directly about how to code. As
This is a code review question more then anything. I have the following problem:
I guess this is more or less a two-part question, but here's the basics
ASP.Net MVC3 is cool and all but I have this question more out of
I had asked this question Adding more attributes to LINQ to SQL entity Now,

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.