GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - itised/CakePHP-NullableBehavior: A simple behavior for CakePHP that inserts a `null` value instead of an empty string when a property value is not set and its corresponding field is nullable.

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

17 Commits
17 Commits

Folders and files

NameName
Last commit message
Last commit date
Model/Behavior
Model/Behavior
 
 
Test
Test
 
 
README.markdown
README.markdown
 
 

Repository files navigation

NullableBehavior

A simple behavior plugin for CakePHP 1.2/1.3/2.x that inserts a null value instead of an empty string when a property value is not set and its corresponding field is nullable.

This behavior is especially useful when foreign key fields are nullable. CakePHP attempts to insert whatever value is assigned to a property. In most cases, this value is generated by a form where empty values are represented by empty strings. If the property is a foreign key, an empty string will generate a database constraint error. A model that actsAs Nullable will not.

This project was recently moved from a simple behavior to a plugin so that it's easier to maintain and install within the context of other projects.

Installation

If you're installing in a code base earlier than 2.x, be sure that you use the code on the 1.3 branch.

As an Archive

  1. Click the big 'ol Downloads button next to the project description.
  2. Extract the archive to app/plugins/nullable.

As a Submodule

  1. $ git submodule add git://github.com/robwilkerson/CakePHP-NullableBehavior.git <path_to>/app/plugins/nullable
  2. $ git submodule init
  3. $ git submodule update
  4. Ensure that you're using the intended branch (may I suggest master?)

Usage

Nullable is one of those behaviors that really just makes an application behave the "right" way and has no negative impact. In every case, I've seen an empty string is applied as a matter of convenience rather than of correctness. To that end, the preferred usage is to apply this behavior to all models. To do so:

  1. Copy <application root>/cake/libs/model/app_model to your <application root>/app/ directory.

  2. Apply the NullableBehavior to the newly copied AppModel.

     class AppModel extends Model {
       public $actsAs = array( 'Nullable.Nullable' );
     
       # 
       # Additional shared model code, as required
       # 
     }
    

Of course, the Nullable behavior can also be applied to a specific model in the same manner outlined above.

License

This code is licensed under the MIT license.

Notes

Feel free to suggest improvements in a ticket or fork this project and improve upon it yourself.

About

A simple behavior for CakePHP that inserts a `null` value instead of an empty string when a property value is not set and its corresponding field is nullable.

Resources

Readme
Activity

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.