PHP code example of ravage84 / cakephp-multi-column-uniqueness

1. Go to this page and download the library: Download ravage84/cakephp-multi-column-uniqueness library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ravage84 / cakephp-multi-column-uniqueness example snippets


public $validate = array(
	'first_name' => array(
		'unique_first_last' => array(
			'rule'    => array('checkMultiColumnUnique', array('first_name', 'last_name'), false)
			'message' => 'The first and last name must be unique.'
		)
	),
	// Additionally/optionally the same for the 'last_name' field
;)


public function checkMultiColumnUnique($ignoredData, $fields, $or = true) {
		return $this->isUnique($fields, $or);
}

public $actsAs = array('MultiColumnUniqueness.MultiColumnUniqueness' => array(
	'fields' => array('name', 'manufacturer_id')
));

public $actsAs = array('MultiColumnUniqueness.MultiColumnUniqueness' => array(
	'fields' => array('name', 'manufacturer_id'),
	'errMsg' => "This name and manufacturer ID can't be used twice."
));

public $actsAs = array('MultiColumnUniqueness.MultiColumnUniqueness' => array(
	'fields' => array(
		array('name', 'manufacturer_id'),
		array('field1', 'field2', 'field3'),
	)
));

public $actsAs = array('MultiColumnUniqueness.MultiColumnUniqueness' => array(
	'fields' => array(
		array('name', 'manufacturer_id'),
		array('field1', 'field2', 'field3'),
	),
	'errMsg' => array(
		"This name and manufacturer ID can't be used twice.",
		"This field1, field2, fiel3 can't be used twice"),
));

public $actsAs = array('MultiColumnUniqueness.MultiColumnUniqueness' => array(
	'fields' => array(
		array('name', 'manufacturer_id'),
		array('field1', 'field2', 'field3'),
	),
	'onlyOnce' => false,
));