Download the PHP package ravage84/cakephp-multi-column-uniqueness without Composer

On this page you can find all versions of the php package ravage84/cakephp-multi-column-uniqueness. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cakephp-multi-column-uniqueness

MultiColumnUniqueness

Travis-CI Build Status Coverage Status Scrutinizer Code Quality Total Downloads Latest Stable Version

A CakePHP 2.x behavior plugin to validate the uniqueness of multiple columns of a model.

Requirements

The plugin has been tested with the following setup(s)

But it should work with

Installation

Using Composer

See the CakePHP plugin installation guide in the CakePHP Cookbook.

Reporting issues

If you have an problem with this plugin please open an issue. But check if the problem has already been reported.

Contributing

If you'd like to contribute to this project, check out the open issues for any planned features or open bugs. You can fork the project, add features, documentation, and send pull requests; or open issues.

Versioning

This plugin adheres to SemVer (Semantic Versioning). Since the API is still in development, the plugin hasn't reached 1.0 yet.

CakePHP Version Support

There are no plans to backport this to CakePHP 1.x. The plugin should be updated to support future 2.x releases. For CakePHP 3.0 it will need a total rewrite most probably...

How To Use

Let's say you have a model Product which has many fields but two of them need to be unique in conjunction with each other. Those fields are name and manufacturer_id.

As you may know you could use the CakePHP built-in data validation rule named isUnique. This rule even takes multiple columns, which you could implement like this:

``

So why bother using this plugin? Because the solution above has a few downsides. First either you setup the same rule for both/all fields that need to be unique or you just set it for one of the fields.

If you set it for all fields the rule will be executed for each field resulting in multiple (and redundant) SQL queries. If you set it for only one field on the other hand, you have to include that field in the data array every time you want to save one of the fields that need to be unique. This plugins circumvents this by adding the rule dynamically.

To enable the MultiColumnUniquenessBehavior for these fields you need to set the $actsAs property in the Product model.

``

This is the simplest form of setup. It would output a The fields mane and manufacturer_id must be unique. error message when the validation fails.

Additionally you could also choose a custom validation error message like this:

``

Now let's say you also have three other fields named field1, field2, field13 which need to be unique in conjunction with each other in the same model. If you don't need custom error messages, you can set it up like this:

``

For the same situation but with custom error messages, do it like this:

``

By default the data validation rule will be added only to the first field which needs to be unique found in the data array. If you want to enforce the data validation on each unique field, set the onlyOnce option to false. This way the validation error message will be shown on each unique field.

`` This option can only be set per model, not per unique field group.

TODOs

Background Story

I needed to validate the uniqueness of two fields of a model. Not separately as CakePHP supports built-in by the isUnique data validation rule but in conjunction with each other. After I didn't found any built-in solution for my problem I turned to Google and found some articles about this. Also I asked dereuromark if he knew if there was an existing solution. He pointed me to his extended model called MyModel in his Tools project.

Those solutions seemed to work but all of them either weren't up to date, weren't clean enough in their approach or forced me to add way too much code for my narrow needs. So I decided to write a behavior for it (my first by the way).

After I got that to work I thought other people could benefit from it, so I created this project and implemented it as a plugin.


All versions of cakephp-multi-column-uniqueness with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
composer/installers Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ravage84/cakephp-multi-column-uniqueness contains the following files

Loading the files please wait ....