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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:36:05+00:00 2026-05-23T11:36:05+00:00

New to CakePHP here – I’m going through the documentation on the site, trying

  • 0

New to CakePHP here – I’m going through the documentation on the site, trying to muster up some basic data validation for a model I’m creating. This will likely be the first of many questions I have about CakePHP.

In the CakePHP Book, the validation rules seem to specify two different methods for making sure that a field isn’t empty – AllowEmpty, and NotEmpty.

Question – is there a tangible difference between these two? CakePHP states that validation rules should occur in your model or controller – is one better suited for a model, and the other for a controller? The Book doesn’t say anything about this. I’m guessing that one is an older method that’s simply still around?

What gives? Should I use a specific one, or both, or does it not matter?

Edit: I decided to check the CakePHP 1.3 class documentation for it (to check the default value of the allowEmpty attribute), but it doesn’t even show up. It’s not in the source code either…is there something I’m missing?

  • 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-23T11:36:06+00:00Added an answer on May 23, 2026 at 11:36 am

    Welcome to Cake. I hope you enjoy it.

    This is definitely one of the stranger aspects of Cake.

    notEmpty is a rule in and of itself. You can define it in your $validation attribute. You can assign a message for when this validation fails. You can treat this as if it is any other validation rule.

    allowEmpty is an option of another validation rule, normally not notEmpty. It is not a validation rule in-and-of-itself. This would allow, for example, you to define that a varchar field allows an empty string, ”, or a string with no more than 20 characters.

    Edit:

    Here’s some code

    // model validation using 'notEmpty'
    $validation = array(
        'fieldName' => array(
            'notEmpty' => array(
                'rule' => 'notEmpty',
                'message' => 'This value may not be left empty!'
            ),
            ... // other rules can go here
        ),
        ... // other fieldName can go here
    );
    
    
    // model validation using 'allowEmpty' to create an optional field
    $validation = array(
        'fieldName' => array(
            'maxLength' => array(
                 'rule' => array('maxLength', 20),
                 'message' => 'This field may only contain 20 characters!',
                 'allowEmpty' => true    // we'll also accept an empty string
            ), 
            ... // other rules can go here
        )
        ... // other fieldName can go here
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to CakePHP and I trying out some of the tutorials on it.
I'm new to CakePHP and am just running through the configuration process, but am
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 new to CakePHP, and I'm trying to decide between the schema shell that
i am new to cakephp, and also new to ajax. the function i trying
I'm fairly new to CakePHP and am trying to setup a custom admin area
Im new to cakePHP, and Im wondering how a 'live' site does this. I
I'm trying to write some beforeSave logic in CakePHP 2.0 beta. Basically I want
Well, I am new to CakePHP. So a painful day to debug this. Here

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.