| Server IP : 210.245.233.93 / Your IP : 216.73.216.226 Web Server : Apache/2.2.15 (CentOS) System : Linux webserver2.onesolution.com.hk 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : apache ( 48) PHP Version : 5.3.3 Disable Function : exec, shell_exec, system, passthru, popen, proc_open, pcntl_exec MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hkosl.com/demo_google/application/libraries/ |
Upload File : |
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use \Illuminate\Database\Capsule\Manager as DB;
class MY_Form_validation extends CI_Form_validation
{
/**
* MY_Form_validation constructor.
* @param array $rules
*/
public function __construct($rules = array())
{
parent::__construct($rules);
}
/**
* Validate datetime format
*
* @param $date
* @return bool
*/
public function validate_datetime($date)
{
if($date) {
$format = 'Y-m-d H:i:s';
$d = DateTime::createFromFormat($format, $date);
if(!$d || $d->format($format) <> $date){
$this->set_message(__FUNCTION__,'{field} '.__('is invalid format.'));
return false;
}
}
return true;
}
/**
* Validate date format
*
* @param $date
* @return bool
*/
public function validate_date($date)
{
if($date) {
$format = 'Y-m-d';
$d = DateTime::createFromFormat($format, $date);
if(!$d || $d->format($format) <> $date){
$this->set_message(__FUNCTION__,'{field} '.__('is invalid format.'));
return false;
}
}
return true;
}
/**
* Is Unique
*
* Check if the input value doesn't already exist
* in the specified database field.
*
* @param string $str
* @param string $field
* @param integer $deleted
* @return bool
*/
public function is_unique($str, $field, $deleted = 0)
{
sscanf($field, '%[^.].%[^.]', $table, $field);
return DB::table($table)->where($field,$str)->where('deleted',$deleted)->count() == 0;
// return isset($this->CI->db)
// ? ($this->CI->db->limit(1)->get_where($table, array($field => $str,'deleted'=>$deleted))->num_rows() === 0)
// : FALSE;
}
}