I'm following a Lynda.com course for CakePHP 2.4.0 and per the material the following code should work but fails with the latter error message:
public $validate = array(
'publication_name' => array(
'words' => array(
'rule' => array('custom', '/([\w.-]+ )+[\w+.-]/'),
'message' => 'The publication name can only contain letters, numbers and spaces.',
)
),
);
"preg_match(): Delimiter must not be alphanumeric or backslash [CORE/Cake/Model/Validator/CakeValidationRule.php, line 281]".
Per my searching, the regex should work as it is using a non-alphanumeric delimiter (/). I'm quite perplexed to say the least.
The only way I have been able to get it to successfully save the record is by removing the custom validation rule (which is not the desired result for a variety of reasons).
Any insight on why this is failing validation? I've diff'd my code against that of the author's exercise files and am not sure what I'm (most likely) over looking...
Thank you in advance for your time and insight. I truly appreciate it.
Source Code for Model, View and Controllers: http://tny.cz/0a995577
CakeValidationRule.php
, that's were rules like'words' => 'string value'
are processed. The regex is totally fine (syntax wise), it must be something else. You'll need to show some more of the involved code, controller action, model, etc... – ndm