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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:23:30+00:00 2026-06-14T20:23:30+00:00

As part of a CakePHP (2.2) app I’m writing in my user controllers admin_add()

  • 0

As part of a CakePHP (2.2) app I’m writing in my user controllers admin_add() I need to have a series of check boxes relating to what documents a user can access. However, I need the results of each check box to go into the same DB field.

For example, say you had 3 checkboxes with the values 1, 2 & 3 – if all three were ticked they would go into the same db field as the following string:

1,2,3

How can I do this?

I know this is messy and normally I’d have this controlled by ACL but the need has arisen to do this differently (mainly due to the way the previous incarnation of this app was written and other factors outside of my control).

Thanks in advance

Update re David’s comment **

I’ve got a slightly amended version of your suggested code as below:

if(isset($this->request->data['User'])){
    foreach($this->request->data['User']['manuals'] as $key => $value) {
    if ($value == 1) {
        $field .= $key .", ";
    }
}
    $this->request->data['User']['manuals'] = rtrim($field, ', ');
}

This code works in fine the controller add() function (writes the correct string to the db as I wanted) but produced the following error when done in the beforeSave() model function

Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Array' in 'field list'

The SQL statement that causes the above error is :

SQL Query: INSERT INTO `cakeapp`.`users` (`webforms_email`, `manuals_email`, `user_status_id`, `view_uat`, `username`, `password`, `forename`, `surname`, `company`, `position`, `version_numbers_id`, `support_case_reference`, `support_web_password`, `group_id`, `manuals`, `modified`, `created`) VALUES ('1', '1', 2, '1', 't800@cyberdyne.com', '48e813c14688aff66054d1f1eb93c02d977648c1', 'T800', '101', 'Cyberdyne', 'terminator', 1, '', '', 14, Array, '2012-11-21 12:28:33', '2012-11-21 12:28:33')

The issue seems to be with the Array its trying to insert rather than the contents of the array. Any ideas? Thanks again for your help.

As requested –

public function beforeSave() {

    // Added this if for cases when user being saved but password isnt set 
    if (isset($this->data['User']['password'])) {       
        $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']);
        return true;
    }


    if(isset($this->request->data['User'])){
        foreach($this->request->data['User']['manuals'] as $key => $value) {
            if ($value == 1) {
                $field .= $key .", ";
            }
        }
        $this->request->data['User']['manuals'] = rtrim($field, ', ');
    }


}

Debug of $this->request->data on add():

array(
'User' => array(
    'password' => '*****',
    'username' => 'test@test.com',
    'forename' => 'James',
    'surname' => 'Jacobs',
    'company' => 'Company name',
    'position' => 'Web dev',
    'version_numbers_id' => '1',
    'support_case_reference' => '',
    'support_web_password' => '',
    'webforms_email' => '0',
    'manuals_email' => '0',
    'group_id' => '14',
    'user_status_id' => '1',
    'view_uat' => '1',
    'manuals' => array(
        (int) 36 => '1',
        (int) 31 => '1',
        (int) 32 => '1',
        (int) 33 => '1',
        (int) 34 => '0',
        (int) 35 => '0',
        (int) 37 => '0',
        (int) 38 => '0',
        (int) 39 => '0',
        (int) 40 => '0',
        (int) 41 => '0',
        (int) 30 => '0',
        (int) 29 => '0',
        (int) 24 => '0',
        (int) 25 => '0',
        (int) 26 => '0',
        (int) 27 => '0',
        (int) 28 => '0',
        (int) 47 => '0',
        (int) 48 => '0',
        (int) 49 => '0',
        (int) 118 => '0',
        (int) 117 => '0',
        (int) 94 => '0',
        (int) 88 => '0',
        (int) 51 => '0',
        (int) 50 => '0',
        (int) 46 => '0',
        (int) 45 => '0',
        (int) 9 => '0',
        (int) 6 => '0',
        (int) 5 => '0',
        (int) 10 => '0',
        (int) 4 => '0',
        (int) 44 => '0',
        (int) 7 => '0',
        (int) 43 => '0',
        (int) 42 => '0',
        (int) 125 => '0',
        (int) 124 => '0',
        (int) 127 => '0',
        (int) 129 => '0',
        (int) 130 => '0',
        (int) 126 => '0',
        (int) 131 => '0',
        (int) 132 => '0',
        (int) 133 => '0',
        (int) 134 => '0',
        (int) 135 => '0',
        (int) 136 => '0',
        (int) 137 => '0',
        (int) 168 => '0',
        (int) 123 => '0',
        (int) 128 => '0',
        (int) 97 => '0',
        (int) 91 => '0',
        (int) 101 => '0',
        (int) 100 => '0',
        (int) 98 => '0',
        (int) 92 => '0',
        (int) 95 => '0',
        (int) 93 => '0',
        (int) 74 => '0',
        (int) 120 => '0',
        (int) 73 => '0',
        (int) 75 => '0',
        (int) 76 => '0',
        (int) 72 => '0',
        (int) 122 => '0',
        (int) 119 => '0',
        (int) 175 => '0',
        (int) 174 => '0',
        (int) 173 => '0',
        (int) 172 => '0',
        (int) 171 => '0',
        (int) 170 => '0',
        (int) 169 => '0',
        (int) 176 => '0'
    ),
    'filename' => array(
        'name' => '',
        'type' => '',
        'tmp_name' => '',
        'error' => (int) 4,
        'size' => (int) 0
    )
)

)

  • 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-14T20:23:31+00:00Added an answer on June 14, 2026 at 8:23 pm

    If I was doing this I would use a model callback function.

    In your User model, I’d create a beforeSave(). Your implementation might differ, but hopefully you get the idea from the below quick example.

    public function beforeSave(){
      if(isset($this->data['User']){
        foreach($this->data['User']['documents'] as $doc){
           $field .= $doc .", ";
        }
        $this->data['User']['allowed_docs'] = rtrim($field, ', ');
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CakePHP 2.0 app that uses the AuthComponent with User model to
I'm working on a CakePHP project and am currently building the user authentication part
As part of a larger web-app (using CakePHP), I'm putting together a simple blog
I'm writing my first CakePHP application and am just writing the second part of
I've got a scaffold built for CakePHP, but need to have a way for
I have developed a CakePHP application that does basic CRUD on a series of
I use CakePHP 2.0 I am following this guide http://nuts-and-bolts-of-cakephp.com/2009/01/19/jquery-in-the-cakephp-world-part-1/ I have included in
Part of my app caches web pages for offline viewing. To do that, I
Part of an app I am working on includes a log file viewer, with
Part of a complex query that our app is running contains the lines: ...(inner

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.