当前位置: 首页>>代码示例>>PHP>>正文


PHP Validate::addRule方法代码示例

本文整理汇总了PHP中Validate::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP Validate::addRule方法的具体用法?PHP Validate::addRule怎么用?PHP Validate::addRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Validate的用法示例。


在下文中一共展示了Validate::addRule方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: loginAction

 public function loginAction()
 {
     $userInfo = Session::get('user');
     if ($userInfo['login'] == true && $userInfo['time'] + TIME_LOGIN >= time()) {
         URL::redirect('admin', 'index', 'index');
     }
     $this->_templateObj->setFolderTemplate('admin/main/');
     $this->_templateObj->setFileTemplate('login.php');
     $this->_templateObj->setFileConfig('template.ini');
     $this->_templateObj->load();
     $this->_view->_title = 'Login';
     if (@$this->_arrParam['form']['token'] > 0) {
         $validate = new Validate($this->_arrParam['form']);
         $username = @$this->_arrParam['form']['username'];
         $password = md5(@$this->_arrParam['form']['passwd']);
         $query = "SELECT `id` FROM `user` WHERE `username` = '{$username}' AND `password` = '{$password}'";
         $validate->addRule('username', 'existRecord', array('database' => $this->_model, 'query' => $query));
         $validate->run();
         if ($validate->isValid() == true) {
             $infoUser = $this->_model->infoItem($this->_arrParam);
             $arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'group_acp' => $infoUser['group_acp']);
             Session::set('user', $arraySession);
             URL::redirect('admin', 'index', 'index');
         } else {
             $this->_view->errors = $validate->showErrors();
         }
     }
     $this->_view->render('index/login', true);
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:29,代码来源:IndexController.php

示例2: loginAction

 public function loginAction()
 {
     $userInfo = Session::get('user');
     if ($userInfo['login'] == true && $userInfo['time'] + TIME_LOGIN >= time()) {
         URL::redirect('default', 'user', 'index');
     }
     $this->_view->_title = 'Login';
     if (@$this->_arrParam['form']['token'] > 0) {
         $validate = new Validate($this->_arrParam['form']);
         $email = $this->_arrParam['form']['email'];
         $password = md5($this->_arrParam['form']['password']);
         $query = "SELECT `id` FROM `user` WHERE `email` = '{$email}' AND `password` = '{$password}'";
         $validate->addRule('email', 'existRecord', array('database' => $this->_model, 'query' => $query));
         $validate->run();
         if ($validate->isValid() == true) {
             $infoUser = $this->_model->infoItem($this->_arrParam);
             $arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'group_acp' => $infoUser['group_acp']);
             Session::set('user', $arraySession);
             URL::redirect('default', 'user', 'index');
         } else {
             $this->_view->errors = $validate->showErrorsPublic();
         }
     }
     $this->_view->render('index/login');
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:25,代码来源:IndexController.php

示例3: formAction

 public function formAction()
 {
     $this->_view->_title = 'User : Add';
     $this->_view->slbGroup = $this->_model->itemInSelectBox($this->_arrParam);
     if (isset($this->_arrParam['id'])) {
         $this->_view->_title = 'User : Edit';
         $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
         if (empty($this->_arrParam['form'])) {
             URL::redirect('admin', 'user', 'index');
         }
     }
     if (@$this->_arrParam['form']['token'] > 0) {
         $task = 'add';
         $requirePass = true;
         $queryUserName = "SELECT `id` FROM `" . TBL_USER . "` WHERE `username` = '{$this->_arrParam['form']['username']}'";
         $queryEmail = "SELECT `email` FROM `" . TBL_USER . "` WHERE `email` = '{$this->_arrParam['form']['email']}'";
         if (isset($this->_arrParam['form']['id'])) {
             $task = 'edit';
             $requirePass = false;
             $queryUserName .= " AND `id` <> '" . $this->_arrParam['form']['id'] . "'";
             $queryEmail .= " AND `id` <> '" . $this->_arrParam['form']['id'] . "'";
         }
         $validate = new Validate($this->_arrParam['form']);
         $validate->addRule('username', 'string-notExistRecord', array('database' => $this->_model, 'query' => $queryUserName, 'min' => 3, 'max' => 25))->addRule('email', 'email-notExistRecord', array('database' => $this->_model, 'query' => $queryEmail))->addRule('password', 'password', array('action' => $task), $requirePass)->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('group_id', 'status', array('deny' => array('default')));
         $validate->run();
         $this->_arrParam['form'] = $validate->getResult();
         if ($validate->isValid() == false) {
             $this->_view->errors = $validate->showErrors();
         } else {
             $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
             // Insert to Database
             $id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
             $type = $this->_arrParam['type'];
             if ($type == 'save-close') {
                 URL::redirect('admin', 'user', 'index');
             }
             if ($type == 'save-new') {
                 URL::redirect('admin', 'user', 'form');
             }
             if ($type == 'save') {
                 URL::redirect('admin', 'user', 'form', array('id' => $id));
             }
         }
     }
     $this->_view->arrParam = $this->_arrParam;
     $this->_view->render('user/form', true);
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:47,代码来源:UserController.php

示例4: formAction

 public function formAction()
 {
     $this->_view->_title = 'Book : Add';
     $this->_view->slbCategory = $this->_model->itemInSelectBox($this->_arrParam);
     if (!empty($_FILES)) {
         $this->_arrParam['form']['picture'] = $_FILES['picture'];
     }
     if (isset($this->_arrParam['id'])) {
         $this->_view->_title = 'Book : Edit';
         $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
         if (empty($this->_arrParam['form'])) {
             URL::redirect('admin', 'book', 'index');
         }
     }
     if (@$this->_arrParam['form']['token'] > 0) {
         $task = 'add';
         if (isset($this->_arrParam['form']['id'])) {
             $task = 'edit';
         }
         $validate = new Validate($this->_arrParam['form']);
         $validate->addRule('name', 'string', array('min' => 1, 'max' => 255))->addRule('picture', 'file', array('min' => 100, 'max' => 1000000, 'extension' => array('jpg', 'png')), false)->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('special', 'status', array('deny' => array('default')))->addRule('category_id', 'status', array('deny' => array('default')))->addRule('sale_off', 'int', array('min' => 0, 'max' => 100))->addRule('price', 'int', array('min' => 1000, 'max' => 1000000));
         $validate->run();
         $this->_arrParam['form'] = $validate->getResult();
         if ($validate->isValid() == false) {
             $this->_view->errors = $validate->showErrors();
         } else {
             $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
             // Insert to Database
             $id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
             $type = $this->_arrParam['type'];
             if ($type == 'save-close') {
                 URL::redirect('admin', 'book', 'index');
             }
             if ($type == 'save-new') {
                 URL::redirect('admin', 'book', 'form');
             }
             if ($type == 'save') {
                 URL::redirect('admin', 'book', 'form', array('id' => $id));
             }
         }
     }
     $this->_view->arrParam = $this->_arrParam;
     $this->_view->render('book/form', true);
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:44,代码来源:BookController.php

示例5: formAction

 public function formAction()
 {
     $this->_view->_title = 'User Category : Add';
     if (!empty($_FILES)) {
         $this->_arrParam['form']['picture'] = $_FILES['picture'];
     }
     if (isset($this->_arrParam['id'])) {
         $this->_view->_title = 'User Category : Edit';
         $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
         if (empty($this->_arrParam['form'])) {
             URL::redirect('admin', 'category', 'index');
         }
     }
     if (@$this->_arrParam['form']['token'] > 0) {
         /*echo '<pre>';
         		print_r($this->_arrParam);
         		echo '</pre>';
         		die("Function die is called");*/
         $validate = new Validate($this->_arrParam['form']);
         $validate->addRule('name', 'string', array('min' => 3, 'max' => 255))->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')))->addRule('picture', 'file', array('min' => 100, 'max' => 1000000, 'extension' => array('jpg', 'png')), false);
         $validate->run();
         $this->_arrParam['form'] = $validate->getResult();
         if ($validate->isValid() == false) {
             $this->_view->errors = $validate->showErrors();
         } else {
             echo $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
             // Insert to Database
             $id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
             $type = $this->_arrParam['type'];
             if ($type == 'save-close') {
                 URL::redirect('admin', 'category', 'index');
             }
             if ($type == 'save-new') {
                 URL::redirect('admin', 'category', 'form');
             }
             if ($type == 'save') {
                 URL::redirect('admin', 'category', 'form', array('id' => $id));
             }
         }
     }
     $this->_view->arrParam = $this->_arrParam;
     $this->_view->render('category/form', true);
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:43,代码来源:CategoryController.php

示例6: login

 public function login()
 {
     if (Session::get('loggedIn') == true) {
         $this->redirect('group', 'index');
     }
     if (isset($_POST['submit'])) {
         $source = array('username' => $_POST['username']);
         $validate = new Validate($source);
         $query = "SELECT `id` FROM `user` WHERE `nickname` = '{$_POST['username']}' AND `position` = '{$_POST['password']}'";
         $validate->addRule('username', 'existRecord', array('database' => $this->db, 'query' => $query));
         $validate->run();
         $error = $validate->getError();
         if ($validate->isValid() == true) {
             Session::set('loggedIn', true);
             $this->redirect('group', 'index');
         } else {
             $this->view->errors = $validate->showErrors();
         }
     }
     $this->view->render('user/login');
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:21,代码来源:user.php

示例7: indexAction

 public function indexAction()
 {
     $this->_view->_title = 'Login';
     $userInfo = Session::get('user');
     if (@$this->_arrParam['loginForm']['token'] > 0) {
         $validate = new Validate($this->_arrParam['loginForm']);
         $username = @$this->_arrParam['loginForm']['username'];
         $password = md5(@$this->_arrParam['loginForm']['password']);
         $query = "SELECT `id` FROM `user` WHERE `nickname` = '{$username}' AND `password` = '{$password}'";
         $validate->addRule('username', 'existRecord', array('database' => $this->_model, 'query' => $query));
         $validate->run();
         if ($validate->isValid() == true) {
             $infoUser = $this->_model->infoItem($this->_arrParam);
             $arraySession = array('login' => true, 'info' => $infoUser, 'time' => time(), 'admin_control' => $infoUser['admin_control']);
             Session::set('user', $arraySession);
             URL::redirect(URL::createLink('default', 'index', 'index'));
         } else {
             $this->_view->errors = $validate->showErrors(false);
         }
     }
     $this->_view->render('login/index', true);
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:22,代码来源:LoginController.php

示例8: formAction

 public function formAction()
 {
     $this->_view->_title = 'Category Manager : Add';
     if (isset($this->_arrParam['id'])) {
         $this->_view->_title = 'Category Manager : Edit';
         $this->_arrParam['form'] = $this->_model->infoItem($this->_arrParam);
         if (empty($this->_arrParam['form'])) {
             URL::redirect(URL::createLink('admin', 'category', 'index'));
         }
     }
     if (@$this->_arrParam['form']['token'] > 0) {
         $validate = new Validate($this->_arrParam['form']);
         $validate->addRule('name', 'string', array('min' => 3, 'max' => 255))->addRule('ordering', 'int', array('min' => 1, 'max' => 100))->addRule('status', 'status', array('deny' => array('default')));
         $validate->run();
         $this->_arrParam['form'] = $validate->getResult();
         if ($validate->isValid() == false) {
             $this->_view->errors = $validate->showErrors();
         } else {
             echo $task = isset($this->_arrParam['form']['id']) ? 'edit' : 'add';
             // Insert to Database
             $id = $this->_model->saveItem($this->_arrParam, array('task' => $task));
             $type = $this->_arrParam['type'];
             if ($type == 'save-close') {
                 URL::redirect(URL::createLink('admin', 'category', 'index'));
             }
             if ($type == 'save-new') {
                 URL::redirect(URL::createLink('admin', 'category', 'form'));
             }
             if ($type == 'save') {
                 URL::redirect(URL::createLink('admin', 'category', 'form', array('id' => $id)));
             }
         }
     }
     $this->_view->arrParam = $this->_arrParam;
     $this->_view->render('category/form', true);
 }
开发者ID:shimia90,项目名称:PHP-Training,代码行数:36,代码来源:CategoryController.php

示例9: json_encode

<?php

require_once "class/Validate.class.php";
$flagType = 'error';
$error = '';
$source = array('name' => $_POST['name'], 'email' => $_POST['email'], 'message' => $_POST['message'], 'file' => $_FILES['attach']);
$validate = new Validate($source);
$validate->addRule('name', 'string', array('min' => 2, 'max' => 50))->addRule('email', 'email')->addRule('message', 'string', array('min' => 5, 'max' => 500))->addRule('file', 'file', array('extension' => array('png', 'jpg'), 'min' => 50, 'max' => 9000000), false);
$validate->run();
if ($validate->isValid() == false) {
    $error = $validate->getError();
} else {
    $flagType = 'success';
}
$response = array('type' => $flagType, 'message' => $error);
echo json_encode($response);
开发者ID:shimia90,项目名称:PHP-Training,代码行数:16,代码来源:process.php

示例10: header

if ($flagRedirect == true) {
    header('location: error.php');
    exit;
}
if (!empty($_POST)) {
    if ($_SESSION['token'] == $_POST['token']) {
        // refresh page
        unset($_SESSION['token']);
        header('location: ' . $linkForm);
        exit;
    } else {
        $_SESSION['token'] = $_POST['token'];
    }
    $source = array('username' => $_POST['username'], 'email' => $_POST['email'], 'password' => $_POST['password'], 'birthday' => $_POST['birthday'], 'status' => $_POST['status'], 'groupid' => $_POST['groupid'], 'ordering' => $_POST['ordering']);
    $validate = new Validate($source);
    $validate->addRule('username', 'string', 2, 50)->addRule('email', 'email')->addRule('password', 'password')->addRule('birthday', 'birthday')->addRule('groupid', 'status')->addRule('ordering', 'int', 1, 10)->addRule('status', 'status');
    $validate->run();
    $outValidate = $validate->getResult();
    if (!$validate->isValid()) {
        $error = $validate->showErrors();
    } else {
        if ($action == 'edit') {
            $where = array(array('id', $id));
            $database->update($outValidate, $where);
        } else {
            if ($action == 'add') {
                $database->insert($outValidate);
                $outValidate = array();
            }
        }
        $success = '<div class="success">Success</div>';
开发者ID:shimia90,项目名称:PHP-Training,代码行数:31,代码来源:form.php


注:本文中的Validate::addRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。