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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:41:00+00:00 2026-05-12T18:41:00+00:00

Okay, this is driving me nuts. I’m working through the IBM CakePHP Tutorial, and

  • 0

Okay, this is driving me nuts. I’m working through the IBM CakePHP Tutorial, and in the first part, I’m at the section where the author is introducing validation rules for form input:

http://www.ibm.com/developerworks/opensource/tutorials/os-php-cake1/section5.html#N107E3

For the life of me, I can’t figure out what’s happening in this line of code:

$this->invalidate('username_unique');

According to the CakePHP documentation, the Model::invalidate() method takes as its first parameter a string that specifiies “The name of the field to invalidate”. How is “username_unique” the name of the field to validate? Looks to me like it should be just plain old “username”. But incredibly enough, the author’s code works, and mine doesn’t when I change “username_unique” to “username” (or even “User.username”), so I’m thinking there might be a serious flaw in the documentation (or very possibly, with me).

[FWIW, I can see that the CakePHP 1.25 provides a better means of doing validation, but I still find it troubling that what seems to be a well-documented method doesn’t seem to be doing what it advertises, and I want to understand why the tutorial code works.]

Can anyone shed any light on this?

  • 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-12T18:41:00+00:00Added an answer on May 12, 2026 at 6:41 pm

    The “magic” is actually in the $form in this case.

    When calling $this->invalidate('username_unique'), Cake takes a note that the field username_unique is invalid. The fact that this field does not actually exist is irrelevant.

    Now, take another look at the actual $form field (slightly reformatted):

    echo $form->input('username', array(
        'after' => $form->error('username_unique', 'The username is taken. Please try again.')
    ));
    

    It’s outputting a normal form field, but “manually” places an error() output after the form field. $form->error('username_unique', $message) means “if there’s an error for the field username_unique, output the message $message“. So you’re actually marking an imaginary field as invalid and are manually outputting an error message for this imaginary field.

    And actually, that’s a load of outdated cr*p you should forget right away. There’s a built-in syntax for multiple validation rules per field, so you can test for character length and uniqueness at the same time and even get different error messages for each error type. There’s even a built-in isUnique rule, so you won’t even have to code a manual uniqueness test.

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

Sidebar

Ask A Question

Stats

  • Questions 289k
  • Answers 289k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer 1) Assuming there is a central repository (which is the… May 13, 2026 at 5:38 pm
  • Editorial Team
    Editorial Team added an answer Use SelectListItems instead of MenuItem: public class OrderItemModel { public… May 13, 2026 at 5:38 pm
  • Editorial Team
    Editorial Team added an answer Pass this not self. self is undefined. Rename the variable… May 13, 2026 at 5:38 pm

Related Questions

This is driving me nuts. I have been at it for over 2 hours
Okay so this was driving me nuts all day. Why does this happen: class
Let me start off by saying Im VERY new to iphone development, but Im
I am writing a project in C++ for an embedded system with no OS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.