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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:44:51+00:00 2026-05-28T06:44:51+00:00

So i use CakePHP 2.0.5 . My model: class User extends AppModel { public

  • 0

So i use CakePHP 2.0.5 .

My model:

class User extends AppModel {
public $name = 'User';
public $validate = array(
    'username' => array(
        'required' => array(
            'rule' => array('notEmpty'),
            'message' => 'A username is required'
        )
    ));}

Then i at controller perform this action it works fine and gives me error because the field username is empty:

$this->User->create();
$this->User->save(array("User"=>array("username"=>"")))

But if i pass the other named field like:

$this->User->create();
$this->User->save(array("User"=>array("something"=>"")))

it does not perform validation on username field and saves empty on database even if i made rule in my model that username value cannot be empty. So where i am wrong?

  • 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-28T06:44:52+00:00Added an answer on May 28, 2026 at 6:44 am

    According to this page, it should be:

    'rule' => 'notEmpty'
    

    (notice the lack of an array surrounding the ‘notEmpty’)

    Although it is shown that way (above) in the CakePHP book in a few places, I personally like doing it like this, as it seems to follow the rest of the validation conventions (and is shown in many places throughout the book as well):

    'allowEmpty' => false,
    

    Secondly, you need to understand the difference between “allowEmpty/notEmpty” and “required”. According to this page:

    The difference between required and allowEmpty can be confusing.
    ‘required’ => true means that you cannot save the model without the
    key for this field being present in $this->data (the check is
    performed with isset); whereas, ‘allowEmpty’ => false makes sure that
    the current field value is nonempty, as described above.

    Basic translation: ‘required’ means any time you save that item, you MUST include that field. While ‘allowEmpty’..etc means IF you pass that field, it can’t be empty.

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

Sidebar

Related Questions

In my CakePHP application, I have a model like this: class Duck extends AppModel
I am new to CakePHP. I would like to use the model validate mechanism,
In my cakephp project, I use afterSave() method of a model class. In this
I want to use a form variable inside a cakephp model class variable $actsAs.Below
Is there any possibility to use the gettext functionallity within the CakePHP model validation
I'm working in a CakePHP Model class, writing a function that is supposed to
How do you use cakephp to count, for example the number of posts, made
I've started to learn how to use the CakePHP framework for a part time
I use Notepad++ and Aptana for editing my CakePHP code? Is there any way
I have used cakePHP 1.2 and know how to use behaviors in it. using

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.