本文整理汇总了PHP中Validate::error方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::error方法的具体用法?PHP Validate::error怎么用?PHP Validate::error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Validate
的用法示例。
在下文中一共展示了Validate::error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _upload_image
public function _upload_image(Validate $array, $input)
{
if ($array->errors()) {
// Don't bother uploading
return;
}
// Get the image from the array
$image = $array[$input];
if (!Upload::valid($image) or !Upload::not_empty($image)) {
// No need to do anything right now
return;
}
if (Upload::valid($image) and Upload::type($image, $this->types)) {
$filename = strtolower(Text::random('alnum', 20)) . '.jpg';
if ($file = Upload::save($image, NULL, $this->directory)) {
Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename);
// Update the image filename
$array[$input] = $filename;
// Delete the temporary file
unlink($file);
} else {
$array->error('image', 'failed');
}
} else {
$array->error('image', 'valid');
}
}
示例2: password_validate
public function password_validate(Validate $array, $field)
{
if ($this->loaded() && !array_key_exists($field, $this->_changed)) {
return TRUE;
}
if (!Validate::min_length($array[$field], 3)) {
$array->error($field, 'min_length', array(5));
return FALSE;
}
if (!Validate::max_length($array[$field], 50)) {
$array->error($field, 'max_length', array(50));
return FALSE;
}
return TRUE;
}
示例3: shop_got_item
public function shop_got_item(Validate $array, $field)
{
$amount = $array[$field];
$cost = $this->item->price * $amount;
// Check if shop got enought items
if ($this->item->amount < $amount) {
$array->error($field, 'not_enough');
return false;
}
// Check if user can afford it
if ($this->character->money < $cost) {
$array->error($field, 'expensive');
return false;
}
}
示例4: existe
/**
* Verifica que la persona exista.
*
* Se utiliza para otorgar las constancias.
*
* @param Validate $array
* @param <type> $campo
*/
public function existe(Validate $array, $campo)
{
if (ORM::factory("persona")->where("cedula", "=", $array[$campo])->count_all() == 0) {
$array->error($campo, "no_existe");
}
return $array;
}
示例5: check_username
/**
* Username callback to check if username is valid
*/
public function check_username(Validate $array, $field)
{
$exists = (bool) DB::select(array('COUNT("*")', 'total_count'))->from('users')->where('username', '=', $array[$field])->execute()->get('total_count');
if (!$exists) {
$array->error($field, 'not_found', array($array[$field]));
}
}
示例6: slug_available
/**
* Does the reverse of unique_key_exists() by triggering error if username exists
* Validation Rule
*
* @param Validate $array validate object
* @param string $field field name
* @param array $errors current validation errors
* @return array
*/
public function slug_available(Validate $array, $field)
{
//die($field);
if ($this->unique_key_exists($field, $array[$field])) {
$array->error($field, 'slug_available', array($array[$field]));
}
}
示例7: check_unique_email
/**
* Validation callback to check that this user has a unique email
*
* @param Validate $array the validate object to use
* @param string $field the field name to check
*
* @return null
*/
public function check_unique_email(Validate $array, $field)
{
$user = new Model_Vendo_User($array[$field]);
// Only error if this is a new or different object
if ($user->id and $user->id != $this->id) {
$array->error($field, 'not_unique');
}
}
示例8: has_category
public function has_category(Validate $array, $field)
{
$photo = (bool) DB::select(array('COUNT("*")', 'records_found'))->from('photos')->where('user_id', '=', Auth::instance()->get_user()->id)->where('category_id', '=', $array[$field])->execute($this->_db)->get('records_found');
if ($photo) {
$array->error($field, 'category', array($array[$field]));
return FALSE;
}
}
示例9: _check_password_matches
/**
* Validate callback wrapper for checking password match
* @param Validate $array
* @param string $field
* @return void
*/
public static function _check_password_matches(Validate $array, $field)
{
$auth = Auth::instance();
if ($array['password'] !== $array[$field]) {
// Re-use the error messge from the 'matches' rule in Validate
$array->error($field, 'matches', array('param1' => 'password'));
}
}
示例10: censor
/**
* Check username for profanity.
*
* @param Validate Validate object
* @param string field name
* @return void
*/
public function censor(Validate $array, $field)
{
$censor = Censor::factory($array[$field]);
if ($censor->is_offensive()) {
$array->error($field, 'censor', array($array[$field]));
return FALSE;
}
}
示例11: _check_password_matches
/**
* Validate callback wrapper for checking password match
* @param Validate $array
* @param string $field
* @return void
*/
public function _check_password_matches(Validate $array, $field)
{
$auth = Auth::instance();
$salt = $auth->find_salt($array['password']);
if ($array['password'] !== $auth->hash_password($array[$field], $salt)) {
// Re-use the error message from the 'matches' rule in Validate
$array->error($field, 'matches', array('param1' => 'password'));
}
}
示例12: _unique_email
public function _unique_email(Validate $array, $field)
{
// check the database for existing records
$email_exists = (bool) ORM::factory('user')->where('email', '=', $array[$field])->where('id', '!=', $this->id)->count_all();
if ($email_exists) {
// add error to validation object
$array->error($field, 'email_exists', array($array[$field]));
}
}
示例13: do_unique_email
/**
* Check to see if the email address is unique
* @param $array
* @param $field
* @param $errors
* @return unknown_type
*/
public function do_unique_email(Validate $array, $field)
{
if (isset($array['u_email'])) {
if ($this->current_user->email_exists($array['u_email'])) {
// Email is not unique, so they have already registered with that email
$array->error($field, 'unique_email', array($array[$field]));
}
}
}
示例14: username_available
/**
* Tests if a username exists in the database
*
* @param Validation
* @param string field to check
* @return array
*/
public function username_available(Validate $array, $field)
{
if ($this->loaded() and !$this->changed($field)) {
return TRUE;
}
// The value is unchanged
if (Sprig::factory($this->_user_model, array($field => $array[$field]))->load(null, FALSE)->count()) {
$array->error($field, 'username_available');
}
}
示例15: validate
public function validate(Validate $array, $field)
{
if (empty($this->_file_errors)) {
return TRUE;
}
foreach ($this->_file_errors as $error) {
$array->error($field, $error);
}
return FALSE;
}