本文整理汇总了PHP中Model::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::validate方法的具体用法?PHP Model::validate怎么用?PHP Model::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model
的用法示例。
在下文中一共展示了Model::validate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doValidate
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->asfGuardUser !== null) {
if (!$this->asfGuardUser->validate($columns)) {
$failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
}
}
if ($this->aModel !== null) {
if (!$this->aModel->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aModel->getValidationFailures());
}
}
if (($retval = ScorePeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
if ($this->collModels !== null) {
foreach ($this->collModels as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
$this->alreadyInValidation = false;
}
return !empty($failureMap) ? $failureMap : true;
}
示例2: validate
/**
* Ensures that a config key has been set before ANY updates allowed
* @param array $fields
* @param string $type insert or update
* @return boolean
*/
public function validate($fields = false, $type = false)
{
$clean = parent::validate($fields, $type);
if ($clean->isEmpty('config_key')) {
$this->addError('config_key', 'The configuration key may not be empty.');
}
return !$this->error();
}
示例3: validate
/**
* Validates the database table input
* @param array $fields
* @param string $primary_key
* @return boolean
* @access public
*/
public function validate($fields = false, $primary_key = false)
{
$clean = parent::validate($fields, $primary_key);
if ($clean->isEmpty('page_title')) {
$this->addError('page_title', 'You must enter a page title.');
}
return !$this->error();
}
示例4: validate
/**
* Validates the database table input
* @param array $fields
* @param string $primary_key
* @return boolean
*/
public function validate($fields = false, $primary_key = false)
{
$clean = parent::validate($fields, $primary_key);
// verify username
if ($clean->isEmpty('name')) {
$this->addError('name', text('db:error:groupname'));
}
return !$this->error();
}
示例5: save
public function save()
{
parent::validate('');
CoOrg::config()->set('blog/enableComments', $this->enableComments);
CoOrg::config()->set('blog/enableCommentsFor', $this->enableCommentsFor);
CoOrg::config()->set('blog/moderation-email', $this->moderationEmail);
CoOrg::config()->set('blog/moderation-time', $this->moderationTime);
CoOrg::config()->save();
}
示例6: validate
/**
* Validates the database table input
* @param array $fields
* @param string $primary_key
* @return boolean
* @access public
*/
public function validate($fields = false, $primary_key = false)
{
$clean = parent::validate($fields, $primary_key);
if ($clean->isEmpty('first_name')) {
$this->addError('first_name', 'You must enter a first name.');
}
if ($clean->isEmpty('last_name')) {
$this->addError('last_name', 'You must enter a last name.');
}
return !$this->error();
}
示例7: validate
/**
*
*/
public function validate($data = array())
{
parent::validate($data);
$year = $data[$this->table_name]['year'];
$month = $data[$this->table_name]['month'];
$day = $data[$this->table_name]['day'];
if (!checkdate((int) $month, (int) $day, (int) $year)) {
$this->err_msg['day'][] = '有効な日付ではありません';
}
return empty($this->err_msg);
}
示例8: validate
public function validate()
{
// Unique
$query = db()->prepare('SELECT id FROM ' . PREFIX . 'users WHERE username = ? LIMIT 1');
$query->bindValue(1, $this['username'], \PDO::PARAM_STR);
$query->execute();
$result = $query->fetch();
if ($result && $result['id'] != $this['id']) {
$this->addError('username', 'unique');
}
return parent::validate();
}
示例9: validate
public function validate()
{
// Unique
if (!$this['id']) {
$query = db()->prepare('SELECT id FROM ' . PREFIX . 'components WHERE project_id = ? AND name = ? LIMIT 1');
$query->bindValue(1, $this['project_id'], \PDO::PARAM_STR);
$query->bindValue(2, $this['name'], \PDO::PARAM_STR);
$query->execute();
$result = $query->fetch();
if ($result && $result['id'] != $this['id']) {
$this->addError('name', 'unique');
}
}
return parent::validate();
}
示例10: validate
/**
*
*/
public function validate($data_array = array())
{
parent::validate($data_array);
$pass = $data_array['team']['password'];
$pass_2 = $data_array['team']['password-2'];
// 入力したパスワードが一致していなかったらエラー
if (!($res = $pass == $pass_2)) {
$this->err_msg['password-2'][] = 'パスワードとパスワード確認が一致しません';
}
// IDとパスワードの組み合わせがユニークか
if ($res = $this->find(array(':login_id' => $data_array['team']['login_id']), 'WHERE login_id = :login_id')) {
$this->err_msg['login_id'][] = 'すでにそのIDは使われています';
}
return empty($this->err_msg);
}
示例11: validate
/**
* Validates the database table input
* @param array $fields
* @param string $primary_key
* @return boolean
* @access public
*/
public function validate($fields = false, $primary_key = false)
{
$clean = parent::validate($fields, $primary_key);
if ($clean->isEmpty('first_name')) {
$this->addError('first_name', text('db:error:first_name'));
}
if ($clean->isEmpty('last_name')) {
$this->addError('last_name', text('db:error:last_name'));
}
// verify username
if ($clean->isEmpty('username')) {
$this->addError('username', text('db:error:username'));
} else {
// if we're adding the record, check for existing username
if (!$primary_key) {
$user = $this->open('users');
$user->where('username', $clean->getEmail('username'));
$unique = $user->results();
if ($unique) {
$this->addError('username', text('db:error:username-dup'));
}
}
}
// verify password (unless both field are sent, password is ignored entirely)
if ($clean->keyExists('_raw_password') && $clean->keyExists('password_confirm')) {
if ($clean->isSetAndEmpty('_raw_password') || $clean->isSetAndEmpty('password_confirm')) {
$this->addError('password', text('db:error:password'));
} else {
if (!$clean->match('_raw_password', 'password_confirm')) {
$this->addError('password', text('db:error:password_match'));
}
}
}
// verify groups
if (!$clean->isEmpty('Groups')) {
// Make sure an admin isn't removing his own admin status
if (defined('IS_ADMIN') && IS_ADMIN && $primary_key == session()->getInt('user_id')) {
if (!$clean->isInArray('Groups', 1)) {
$this->addError('Groups', text('db:error:groups-noadmin'));
}
}
}
// if we're inserting new record, no empty pass
if (!$primary_key && $clean->isEmpty('password')) {
$this->addError('password', text('db:error:password'));
}
return !$this->error();
}
示例12: validate
/**
* バリデート処理
*/
public function validate($data, &$valid_data, $white_list = array())
{
// バリデートを定義
$this->validates = array('title' => array('required' => true, 'maxlength' => array('max' => 50)), 'title_align' => array('default_value' => 'left', 'in_array' => array('values' => array_keys(self::getAttributeAlign()))), 'title_color' => array('default_value' => '', 'in_array' => array('values' => array_keys(self::getAttributeColor()))), 'contents' => array('required' => true, 'maxlength' => array('max' => 100000), 'own' => array('method' => 'fc2PluginSyntax')), 'contents_align' => array('default_value' => 'left', 'in_array' => array('values' => array_keys(self::getAttributeAlign()))), 'contents_color' => array('default_value' => '', 'in_array' => array('values' => array_keys(self::getAttributeColor()))), 'device_type' => array('default_value' => Config::get('DEVICE_PC'), 'in_array' => array('values' => array_keys(Config::get('DEVICE_NAME')))), 'category' => array('default_value' => 1, 'in_array' => array('values' => array(1, 2, 3))));
$errors = parent::validate($data, $valid_data, $white_list);
if (!empty($errors)) {
return $errors;
}
// title_align,title_color...をattributesに纏める
if (in_array('title_align', $white_list) || in_array('title_color', $white_list) || in_array('contents_align', $white_list) || in_array('contents_color', $white_list)) {
$attribute = array('title_align' => $valid_data['title_align'], 'title_color' => $valid_data['title_color'], 'contents_align' => $valid_data['contents_align'], 'contents_color' => $valid_data['contents_color']);
$valid_data['attribute'] = json_encode($attribute);
unset($valid_data['title_align'], $valid_data['title_color'], $valid_data['contents_align'], $valid_data['contents_color']);
}
return $errors;
}
示例13: validate
/**
* Checks if given model is valid
*
* If every validation passes, returns true. Else, returns an array of names of
* failed validations in following format:
* array(field=>array(validation[, ...]))
*
* @param Model $model
* @return mixed
*/
public static function validate($model)
{
$model->validate();
$failures = [];
foreach (self::$results[get_class($model)] as $field => $validations) {
foreach ($validations as $validation => $result) {
if ($result === false) {
$failures[$field][] = $validation;
}
}
}
if (empty($failures) !== true) {
return $failures;
} else {
return true;
}
}
示例14: validate
/**
* Validates the database table input
* @param array $fields
* @param string $primary_key
* @return boolean
* @access public
*/
public function validate($fields = false, $primary_key = false)
{
$clean = parent::validate($fields, $primary_key);
if ($clean->isEmpty('title')) {
$this->addError('title', 'You must enter a title.');
}
if (!$clean->isEmpty('recurring') && !$clean->isDate('start_date')) {
$this->addError('start_date', 'Please enter a valid start date.');
}
if (!$this->isEmpty('end_date')) {
if ($this->isDate('end_date')) {
if (strtotime($this->getRaw('start_date')) > strtotime($this->getRaw('end_date'))) {
$this->addError('content', 'Please choose a starting date that occurs before the end date.');
}
} else {
$this->addError('end_date', 'Please enter a valid end date.');
}
}
return !$this->error();
}
示例15: validate
protected function validate($t)
{
parent::validate($t);
$user = $this->user();
if ($user == null)
{
$this->username_error = t('Incorrect username');
throw new ValidationException($this);
}
if ($user->isLocked())
{
$this->username_error = t('User is not activated');
throw new ValidationException($this);
}
if (!$user->checkPassword($this->password))
{
$this->password_error = t('Incorrect password');
throw new ValidationException($this);
}
}