本文整理汇总了PHP中Model::invalidate方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::invalidate方法的具体用法?PHP Model::invalidate怎么用?PHP Model::invalidate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::invalidate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateCaptcha
/**
* Validates the captcha responses status set by the component to the model
*
* @param Model $Model Model using this behavior
* @return boolean
* @see RecaptchaComponent::initialize()
*/
public function validateCaptcha(Model $Model)
{
if (isset($Model->recaptcha) && $Model->recaptcha === false) {
$Model->invalidate($this->settings[$Model->alias]['errorField'], $Model->recaptchaError);
}
return true;
}
示例2: validateCaptcha
/**
* Validates the captcha responses status set by the component to the model
*
* @object Model instance
* @return boolean
* @see RecaptchaComponent::initialize()
*/
public function validateCaptcha(Model $Model)
{
//debug($Model->recaptcha);
//$Model->validationErrors['daco'][0] = 'Error';
if (isset($Model->recaptcha) && $Model->recaptcha == false) {
$Model->invalidate($this->settings[$Model->alias]['errorField'], $Model->recaptchaError);
}
return true;
}
示例3: confirm
/**
* The actual logic
*
* @param object $Model Model about to be saved.
* @return bool true if save should proceed, false otherwise
*/
public function confirm(Model $Model, $return = true)
{
$field = $this->settings[$Model->alias]['field'];
$message = $this->settings[$Model->alias]['message'];
if (empty($Model->data[$Model->alias][$field])) {
$Model->invalidate($field, __($message));
return false;
}
return $return;
}
示例4: beforeValidate
public function beforeValidate(Model $Model, $options = array())
{
extract($this->settings[$Model->alias]);
if (!isset($Model->data[$Model->alias][$field]) || !empty($Model->data[$Model->alias][$field])) {
$Model->invalidate($errorField, $message);
$this->log('HoneypotBehavior::beforeValidate() caught: ' . serialize($Model->data));
return false;
}
return true;
}
示例5: beforeSave
/**
* beforeSave
*
* @param Model $model
* @param Model $options
* @return void
* @access public
*/
function beforeSave(&$model, $options)
{
if (!$model->exists()) {
$ret = $this->PluginContent->find(array('PluginContent.name' => $model->data[$model->alias]['name']));
if ($ret) {
// 新規登録で既に登録されている場合は、重複エラーとする
$model->invalidate('name', '既に登録されています。');
return false;
}
$pluginContent = $this->_generatePluginContentData($model);
$this->PluginContent->create($pluginContent);
} else {
$pluginContent = $this->_generatePluginContentData($model, $model->data[$model->alias]['id']);
$this->PluginContent->set($pluginContent);
}
// バリデーション
return $this->PluginContent->validates();
}
示例6: confirm
/**
* Run before a model is saved, used...
*
* @param object $Model Model about to be saved.
* @return boolean true if save should proceed, false otherwise
*/
public function confirm(Model $Model, $return = true)
{
$discountCode = (array) $Model->Session->read('DiscountCode');
if (empty($discountCode)) {
return true;
}
$discount = $this->Discount->get($discountCode['discount_id']);
$orderId = $Model->Session->read('Order.id');
if ($Model->alias === 'Order') {
$this->Order = $Model;
} else {
$this->Order = ClassRegistry::init('Order');
}
$cartItems = $this->Order->getCartItems($orderId);
$discount = array_merge(array('DiscountCode' => $discountCode), $discount);
$value = Order::calcTotal($cartItems);
$res = $this->Discount->DiscountCode->isValid($discount, $value);
if ($res === true) {
return true;
}
$Model->invalidate('code', $res);
return $return;
}
示例7: validateAllowedMimeTypes
/**
* Validates if the mime type of an uploaded file is allowed
*
* @param Model $Model
* @param array Array of allowed mime types
* @return boolean
*/
public function validateAllowedMimeTypes(Model $Model, $mimeTypes = array())
{
extract($this->settings[$Model->alias]);
if (!empty($mimeTypes)) {
$allowedMime = $mimeTypes;
}
$File = new File($Model->data[$Model->alias][$fileField]['tmp_name']);
$mimeType = $File->mime();
if (!in_array($mimeType, $allowedMime)) {
$this->uploadError = __d('file_storage', 'You are not allowed to upload files of this type.');
$Model->invalidate($fileField, $this->uploadError);
return false;
}
return true;
}
示例8: geocode
/**
* Run before a model is saved, used to set up slug for model.
*
* @param object $Model Model about to be saved.
* @return bool True if save should proceed, false otherwise
*/
public function geocode(Model $Model, $return = true)
{
// Make address fields an array
if (!is_array($this->settings[$Model->alias]['address'])) {
$addressfields = array($this->settings[$Model->alias]['address']);
} else {
$addressfields = $this->settings[$Model->alias]['address'];
}
$addressfields = array_unique($addressfields);
// Make sure all address fields are available
if ($this->settings[$Model->alias]['real']) {
foreach ($addressfields as $field) {
if (!$Model->hasField($field)) {
return $return;
}
}
}
$addressData = array();
foreach ($addressfields as $field) {
if (!empty($Model->data[$Model->alias][$field])) {
$addressData[] = $Model->data[$Model->alias][$field];
}
}
$Model->data[$Model->alias]['geocoder_result'] = array();
if ((!$this->settings[$Model->alias]['real'] || $Model->hasField($this->settings[$Model->alias]['lat']) && $Model->hasField($this->settings[$Model->alias]['lng'])) && ($this->settings[$Model->alias]['overwrite'] || empty($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']]) || (int) $Model->data[$Model->alias][$this->settings[$Model->alias]['lat']] === 0 && (int) $Model->data[$Model->alias][$this->settings[$Model->alias]['lng']] === 0)) {
if (!empty($Model->whitelist) && (!in_array($this->settings[$Model->alias]['lat'], $Model->whitelist) || !in_array($this->settings[$Model->alias]['lng'], $Model->whitelist))) {
return $return;
}
}
$geocode = $this->_geocode($addressData, $this->settings[$Model->alias]);
if (empty($geocode) && !empty($this->settings[$Model->alias]['allowEmpty'])) {
return true;
}
if (empty($geocode)) {
return false;
}
// If both are 0, thats not valid, otherwise continue
if (empty($geocode['lat']) && empty($geocode['lng'])) {
// Prevent 0 inserts of incorrect runs
if (isset($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']])) {
unset($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']]);
}
if (isset($Model->data[$Model->alias][$this->settings[$Model->alias]['lng']])) {
unset($Model->data[$Model->alias][$this->settings[$Model->alias]['lng']]);
}
if ($this->settings[$Model->alias]['require']) {
if ($fields = $this->settings[$Model->alias]['invalidate']) {
$Model->invalidate($fields[0], $fields[1], isset($fields[2]) ? $fields[2] : true);
}
return false;
}
return true;
}
// Valid lat/lng found
$Model->data[$Model->alias][$this->settings[$Model->alias]['lat']] = $geocode['lat'];
$Model->data[$Model->alias][$this->settings[$Model->alias]['lng']] = $geocode['lng'];
if (!empty($this->settings[$Model->alias]['formatted_address'])) {
$Model->data[$Model->alias][$this->settings[$Model->alias]['formatted_address']] = $geocode['formatted_address'];
} else {
if (isset($Model->data[$Model->alias][$this->settings[$Model->alias]['formatted_address']])) {
unset($Model->data[$Model->alias][$this->settings[$Model->alias]['formatted_address']]);
}
}
$Model->data[$Model->alias]['geocoder_result'] = $geocode;
$Model->data[$Model->alias]['geocoder_result']['address_data'] = implode(' ', $addressData);
if (!empty($this->settings[$Model->alias]['update'])) {
foreach ($this->settings[$Model->alias]['update'] as $key => $field) {
if (!empty($geocode[$key])) {
$Model->data[$Model->alias][$field] = $geocode[$key];
}
}
}
return $return;
}
示例9: beforeValidate
/**
* Preparing the data
*
* @return bool Success
*/
public function beforeValidate(Model $Model, $options = [])
{
$formField = $this->settings[$Model->alias]['formField'];
$formFieldRepeat = $this->settings[$Model->alias]['formFieldRepeat'];
$formFieldCurrent = $this->settings[$Model->alias]['formFieldCurrent'];
// Make sure fields are set and validation rules are triggered - prevents tempering of form data
if (!isset($Model->data[$Model->alias][$formField])) {
$Model->data[$Model->alias][$formField] = '';
}
if ($this->settings[$Model->alias]['confirm'] && !isset($Model->data[$Model->alias][$formFieldRepeat])) {
$Model->data[$Model->alias][$formFieldRepeat] = '';
}
if ($this->settings[$Model->alias]['current'] && !isset($Model->data[$Model->alias][$formFieldCurrent])) {
$Model->data[$Model->alias][$formFieldCurrent] = '';
}
// Check if we need to trigger any validation rules
if (!$this->settings[$Model->alias]['require']) {
$current = !empty($Model->data[$Model->alias][$formFieldCurrent]);
$new = !empty($Model->data[$Model->alias][$formField]) || !empty($Model->data[$Model->alias][$formFieldRepeat]);
if (!$new && !$current) {
//$Model->validator()->remove($formField); // tmp only!
//unset($Model->validate[$formField]);
unset($Model->data[$Model->alias][$formField]);
if ($this->settings[$Model->alias]['confirm']) {
//$Model->validator()->remove($formFieldRepeat); // tmp only!
//unset($Model->validate[$formFieldRepeat]);
unset($Model->data[$Model->alias][$formFieldRepeat]);
}
if ($this->settings[$Model->alias]['current']) {
//$Model->validator()->remove($formFieldCurrent); // tmp only!
//unset($Model->validate[$formFieldCurrent]);
unset($Model->data[$Model->alias][$formFieldCurrent]);
}
return true;
}
// Make sure we trigger validation if allowEmpty is set but we have the password field set
if ($new) {
if ($this->settings[$Model->alias]['confirm'] && empty($Model->data[$Model->alias][$formFieldRepeat])) {
$Model->invalidate($formFieldRepeat, __d('tools', 'valErrPwdNotMatch'));
}
}
}
// Update whitelist
$this->_modifyWhitelist($Model);
return true;
}
示例10: beforeValidate
/**
* beforeValidate callback
*
* @param Model $Model Model using this behavior
* @return boolean False or null will abort the operation. Any other result will continue.
*/
public function beforeValidate(Model $Model)
{
if (isset($Model->data[$Model->alias][self::TAG_FIELD])) {
$tags = $this->TagCollection->parseTags($Model->data[$Model->alias][self::TAG_FIELD]);
if (empty($tags)) {
return true;
}
// check number of tags
if (isset($this->settings[$Model->alias]['maxTags']) && count($tags) > $this->settings[$Model->alias]['maxTags']) {
$Model->invalidate(self::TAG_FIELD, __('Too many tags. Maximum number of tags: %d', $this->settings[$Model->alias]['maxTags']));
return false;
}
// check length of tags
foreach ($tags as $tag) {
$this->Tag->create();
$this->Tag->set('name', $tag);
if (!$this->Tag->validates()) {
$Model->invalidate(self::TAG_FIELD, __('Invalid tag: %s. Max length: %d', $tag, Tag::NAME_MAX_LENGTH));
return false;
}
}
}
return true;
}
示例11: invalidate
/**
* Overloading AppModel invalidate to include l18n
*
* @param string $field
* @param bool $value
*/
function invalidate($field, $value = true)
{
return parent::invalidate($field, __($value, true));
}
示例12: upload
/**
* Move uploaded file to target location
*
* @param Model $model
* @return boolean
*/
public function upload(Model &$model)
{
$__uploadField = $this->settings[$model->alias]['uploadFields']['file'];
//remove bad characters from name
$model->data[$model->alias]['basename'] = preg_replace('/' . $this->settings[$model->alias]['nameInvalidRegex'] . '/i', $this->settings[$model->alias]['nameInvalidSlug'], $model->data[$model->alias]['basename']);
//check upload target / create unique basename / file overwritting
$uploadPath = $this->_getAbsolutePath($model->data[$model->alias]['path']);
$uploadFile = $model->data[$model->alias]['basename'];
$uploadTarget = $uploadPath . $uploadFile;
if (file_exists($uploadTarget) && $this->settings[$model->alias]['allowOverwrite'] === false) {
if ($this->settings[$model->alias]['nameUnique'] === true) {
$i = 0;
$_info = pathinfo($uploadTarget);
do {
$_newBasename = sprintf("%s-%d", $_info['filename'], ++$i);
$_newBasename .= $_info['extension'] ? "." . $_info['extension'] : "";
//support files without extension
$_uniqueUploadTarget = $uploadPath . $_newBasename;
} while (file_exists($_uniqueUploadTarget));
$uploadTarget = $_uniqueUploadTarget;
$model->data[$model->alias]['basename'] = $_newBasename;
} else {
$model->invalidate($__uploadField, __d('media', "A file with the same name already exists"));
return false;
}
}
//uploaded_file
if (isset($model->data[$model->alias]['tmp_name']) && !is_uploaded_file($model->data[$model->alias]['tmp_name'])) {
$model->invalidate($__uploadField, __d('media', "File was not uploaded properly"));
return false;
} elseif (isset($model->data[$model->alias]['tmp_name']) && !$this->_moveUploadedFile($model->data[$model->alias]['tmp_name'], $uploadTarget)) {
$model->invalidate($__uploadField, __d('media', "Failed to store uploaded file"));
return false;
}
return true;
}
示例13: geocode
/**
* Run before a model is saved, used to set up slug for model.
*
* @param object $Model Model about to be saved.
* @return boolean true if save should proceed, false otherwise
*/
public function geocode(Model $Model, $return = true)
{
// Make address fields an array
if (!is_array($this->settings[$Model->alias]['address'])) {
$addressfields = array($this->settings[$Model->alias]['address']);
} else {
$addressfields = $this->settings[$Model->alias]['address'];
}
$addressfields = array_unique($addressfields);
// Make sure all address fields are available
if ($this->settings[$Model->alias]['real']) {
foreach ($addressfields as $field) {
if (!$Model->hasField($field)) {
return $return;
}
}
}
$adressdata = array();
foreach ($addressfields as $field) {
if (!empty($Model->data[$Model->alias][$field])) {
$adressdata[] = $Model->data[$Model->alias][$field];
}
}
$Model->data[$Model->alias]['geocoder_result'] = array();
// See if we should request a geocode //TODO: reverse and return here
if ((!$this->settings[$Model->alias]['real'] || $Model->hasField($this->settings[$Model->alias]['lat']) && $Model->hasField($this->settings[$Model->alias]['lng'])) && ($this->settings[$Model->alias]['overwrite'] || (empty($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']]) || $Model->data[$Model->alias][$this->settings[$Model->alias]['lat']] == 0 && $Model->data[$Model->alias][$this->settings[$Model->alias]['lat']] == 0))) {
if (!empty($Model->whitelist) && (!in_array($this->settings[$Model->alias]['lat'], $Model->whitelist) || !in_array($this->settings[$Model->alias]['lng'], $Model->whitelist))) {
/** HACK to prevent 0 inserts if not wanted! just use whitelist now to narrow fields down - 2009-03-18 ms */
//$Model->whitelist[] = $this->settings[$Model->alias]['lat'];
//$Model->whitelist[] = $this->settings[$Model->alias]['lng'];
return $return;
}
$geocode = $this->_geocode($adressdata, $this->settings[$Model->alias]);
if (empty($geocode) && !empty($this->settings[$Model->alias]['allowEmpty'])) {
return true;
}
if (empty($geocode)) {
return false;
}
if (!empty($geocode['type']) && !empty($this->settings[$Model->alias]['expect'])) {
if (!in_array($geocode['type'], (array) $this->settings[$Model->alias]['expect'])) {
return $return;
}
}
//pr($geocode);
//pr($this->Geocode->getResult());
// Now set the geocode as part of the model data to be saved, making sure that
// we are on the white list of fields to be saved
//pr ($Model->whitelist); die();
//pr($geocode); die();
# if both are 0, thats not valid, otherwise continue
if (!empty($geocode['lat']) || !empty($geocode['lng'])) {
/** HACK to prevent 0 inserts of incorrect runs - 2009-04-07 ms */
$Model->data[$Model->alias][$this->settings[$Model->alias]['lat']] = $geocode['lat'];
$Model->data[$Model->alias][$this->settings[$Model->alias]['lng']] = $geocode['lng'];
} else {
if (isset($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']])) {
unset($Model->data[$Model->alias][$this->settings[$Model->alias]['lat']]);
}
if (isset($Model->data[$Model->alias][$this->settings[$Model->alias]['lng']])) {
unset($Model->data[$Model->alias][$this->settings[$Model->alias]['lng']]);
}
if ($this->settings[$Model->alias]['require']) {
if ($fields = $this->settings[$Model->alias]['invalidate']) {
$Model->invalidate($fields[0], $fields[1], isset($fields[2]) ? $fields[2] : true);
}
return false;
}
}
if (!empty($this->settings[$Model->alias]['formatted_address'])) {
$Model->data[$Model->alias][$this->settings[$Model->alias]['formatted_address']] = $geocode['formatted_address'];
} else {
if (isset($Model->data[$Model->alias][$this->settings[$Model->alias]['formatted_address']])) {
unset($Model->data[$Model->alias][$this->settings[$Model->alias]['formatted_address']]);
}
}
if (!empty($geocode['inconclusive'])) {
$Model->data[$Model->alias]['geocoder_inconclusive'] = $geocode['inconclusive'];
$Model->data[$Model->alias]['geocoder_results'] = $geocode['results'];
} else {
$Model->data[$Model->alias]['geocoder_result'] = $geocode;
}
$Model->data[$Model->alias]['geocoder_result']['address_data'] = implode(' ', $adressdata);
if (!empty($this->settings[$Model->alias]['update'])) {
foreach ($this->settings[$Model->alias]['update'] as $key => $field) {
if (!empty($geocode[$key])) {
$Model->data[$Model->alias][$field] = $geocode[$key];
}
}
}
# correct country id if necessary
/*
if (in_array('country_name', $this->settings[$Model->alias]['address'])) {
App::uses('Country', 'Tools.Model');
//.........这里部分代码省略.........
示例14: invalidate
/**
* Overwrite invalidate to allow last => true
*
* @param string $field The name of the field to invalidate
* @param mixed $value Name of validation rule that was not failed, or validation message to
* be returned. If no validation key is provided, defaults to true.
* @param bool $last If this should be the last validation check for this validation run
* @return void
*/
public function invalidate($field, $value = true, $last = false)
{
parent::invalidate($field, $value);
if (!$last) {
return;
}
$this->validator()->remove($field);
}
示例15: checkErrors
/**
* Validation d'un champ dans un model
*
* @param Model $model Model
* @param string $filename Nom du champs à valider
* @return bool
*/
public function checkErrors($model, $fieldName, $field)
{
$image = $model->data[$model->alias][$fieldName];
$ok = false;
if (!isset($image['error']) || $image['error'] == UPLOAD_ERR_NO_FILE) {
if (isset($field['validation']) && $field['validation'] == 'notEmpty') {
$model->invalidate($fieldName, __('L\'image est obligatoire.'));
$ok = false;
} else {
$ok = true;
}
} elseif ($image['error'] == UPLOAD_ERR_OK) {
if (!$this->checkSourceType($image['tmp_name'])) {
$model->invalidate($fieldName, __('L\'image doit être de type jpg, png ou gif'));
$ok = false;
} else {
$ok = true;
}
} elseif ($image['error'] == UPLOAD_ERR_INI_SIZE || $image['error'] == UPLOAD_ERR_FORM_SIZE) {
$model->invalidate($fieldName, __('Votre image est trop lourde.'));
$ok = false;
} else {
$model->invalidate($fieldName, __('Une erreur est survenue lors du téléchargement de l\'image.'));
$ok = false;
}
return $ok;
}