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


PHP validate::setRules方法代码示例

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


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

示例1: _doLogin

 protected function _doLogin()
 {
     $rules = array('email' => array('label' => __('email', 'users'), 'rules' => array('trim', 'required', 'max_length' => 255, 'callback__is_valid_login')), 'password' => array('label' => __('password', 'users'), 'rules' => array('trim', 'required', 'min_length' => 4, 'max_length' => 128)), 'remember' => array('label' => __('remember_me', 'users')));
     if (uri::segment(4) == 'license' && !input::demo(0, '', false)) {
         $rules['license'] = array('label' => __('license_new', 'system_license'), 'rules' => array('trim', 'required', 'callback__is_valid_license'));
     }
     validate::setRules($rules);
     if (!validate::run()) {
         return false;
     }
     if (!($user = $this->users_model->getUser(input::post('email'), false, false))) {
         validate::setFieldError('email', __((strpos(input::post('email'), '@') === false ? 'username' : 'email') . '_invalid', 'users_signup'));
         return false;
     }
     if (!$this->users_model->verifyPassword(input::post('password'), $user['password'], $user['user_id'])) {
         validate::setFieldError('password', __('password_invalid', 'users_signup'));
         return false;
     }
     if (uri::segment(4) == 'license' && !input::demo(0, '', false)) {
         $access = $this->users_model->getPermissions($user['group_id'], 'system', 'license_manage');
         if ($access) {
             loader::model('system/license');
             $this->license_model->changeLicense(input::post('license'));
         }
     }
     $this->users_model->login($user['user_id'], input::post('remember'), $user);
     if (uri::segment(4) == 'license') {
         router::redirect('cp/help/license');
     } else {
         router::redirect('cp');
     }
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:32,代码来源:users.php

示例2: _sendFeedback

 protected function _sendFeedback()
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Extra rules
     $rules = array('name' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 2, 'max_length' => 255)), 'email' => array('rules' => array('required', 'is_string', 'trim', 'valid_email', 'min_length' => 4, 'max_length' => 255)), 'subject' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 5, 'max_length' => 255)), 'message' => array('rules' => array('required', 'is_string', 'trim', 'min_length' => 10, 'max_length' => 10000)));
     if (config::item('feedback_captcha', 'feedback') == 1 || config::item('feedback_captcha', 'feedback') == 2 && !users_helper::isLoggedin()) {
         $rules['captcha'] = array('rules' => array('is_captcha'));
     }
     validate::setRules($rules);
     // Validate form values
     if (!validate::run($rules)) {
         return false;
     }
     // Get values
     $email = input::post('email');
     $subject = input::post('subject');
     $message = input::post('message') . "\n\n--\n" . input::post('name') . ' <' . input::post('email') . '>' . "\n" . input::ipaddress();
     // Send feedback
     if (!$this->feedback_model->sendFeedback($email, $subject, $message)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('send_error', 'system'));
         }
         return false;
     }
     // Success
     view::setInfo(__('message_sent', 'feedback'));
     router::redirect('feedback');
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:31,代码来源:feedback.php

示例3: _saveGroup

 protected function _saveGroup($groupID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('name' => array('label' => __('name', 'system'), 'rules' => array('trim', 'required', 'max_length' => 255)), 'keyword' => array('label' => __('keyword', 'system'), 'rules' => array('trim', 'required', 'max_length' => 128, 'alpha_dash', 'strtolower', 'callback__is_unique_keyword' => $groupID)));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $groupData = input::post(array('name', 'keyword'));
     // Save banner group
     if (!($groupID = $this->banners_groups_model->saveGroup($groupID, $groupData))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     // Success
     view::setInfo(__('group_saved', 'banners'));
     router::redirect('cp/content/banners/groups/edit/' . $groupID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:25,代码来源:groups.php

示例4: _saveNewsletter

 protected function _saveNewsletter($newsletterID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('category_id' => array('label' => __('gift_category', 'gifts'), 'rules' => array('intval')));
     // Get newsletter data
     $newsletterData = $input = array();
     $rules['subject'] = array('label' => __('newsletter_subject', 'newsletters'), 'rules' => array('trim', 'required', 'max_length' => 255));
     $rules['message_html'] = array('label' => __('newsletter_message_html', 'newsletters'), 'rules' => array('trim', 'required'));
     $rules['message_text'] = array('label' => __('newsletter_message_text', 'newsletters'), 'rules' => array('trim', 'required'));
     $input = array('subject', 'message_html', 'message_text');
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get newsletter data
     $newsletter = input::post($input);
     // Save newsletter
     if (!($newsletterID = $this->newsletters_model->saveNewsletter($newsletterID, $newsletter))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     router::redirect('cp/content/newsletters/' . (uri::segment(6) == 'review' ? 'review' : 'recipients') . '/' . $newsletterID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:29,代码来源:newsletters.php

示例5: _savePackage

 protected function _savePackage($packageID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('credits' => array('label' => __('credits', 'billing_credits'), 'rules' => array('trim', 'required', 'is_natural_no_zero')), 'price' => array('label' => __('price', 'billing'), 'rules' => array('trim', 'required', 'numeric')), 'active' => array('label' => __('active', 'system'), 'rules' => array('trim', 'required', 'intval')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $package = input::post(array('credits', 'price', 'active'));
     // Save banner group
     if (!($packageID = $this->credits_model->savePackage($packageID, $package))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     // Success
     view::setInfo(__('package_saved', 'billing_credits'));
     router::redirect('cp/billing/credits/edit/' . $packageID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:25,代码来源:credits.php

示例6: _saveTemplate

 protected function _saveTemplate($templateID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array('category_id' => array('label' => __('gift_category', 'gifts'), 'rules' => array('intval')));
     // Get template data
     $rules['name'] = array('label' => __('name', 'system'), 'rules' => array('trim', 'required', 'max_length' => 255));
     $rules['subject'] = array('label' => __('newsletter_subject', 'newsletters'), 'rules' => array('trim', 'required', 'max_length' => 255));
     $rules['message_html'] = array('label' => __('newsletter_message_html', 'newsletters'), 'rules' => array('trim', 'required'));
     $rules['message_text'] = array('label' => __('newsletter_message_text', 'newsletters'), 'rules' => array('trim', 'required'));
     $input = array('name', 'subject', 'message_html', 'message_text');
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get template data
     $template = input::post($input);
     // Save template
     if (!($templateID = $this->newsletters_templates_model->saveTemplate($templateID, $template))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     // Success
     view::setInfo(__('template_saved', 'newsletters_templates'));
     router::redirect('cp/content/newsletters/templates/edit/' . $templateID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:31,代码来源:templates.php

示例7: _submitReport

 protected function _submitReport($resource, $resourceID, $userID, $itemID, $subjects)
 {
     // Extra rules
     $rules = array('subject' => array('rules' => $subjects ? array('required', 'callback__is_valid_subject' => array($subjects)) : array('callback__is_valid_subject' => array($subjects))), 'message' => array('rules' => array('is_string', 'trim', 'max_length' => 255)));
     validate::setRules($rules);
     // Validate form values
     if (!validate::run($rules)) {
         return false;
     }
     // Get values
     $subject = $subjects ? (int) input::post('subject') : 0;
     $message = input::post('message');
     // Send feedback
     if (!$this->reports_model->saveReport($resourceID, $userID, $itemID, $subject, $message)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Success
     router::redirect('report/sent' . (input::get('modal') ? '?modal=1' : ''));
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:22,代码来源:report.php

示例8: _saveComment

 protected function _saveComment($resource, $itemID)
 {
     // Is user logged in?
     if (!users_helper::isLoggedin()) {
         return false;
     }
     // Create rules
     $rules = array('comment' => array('label' => __('comment_body', 'comments'), 'rules' => array('trim', 'required', 'min_length' => config::item('min_length', 'comments'), 'max_length' => config::item('max_length', 'comments'), 'callback__is_comments_delay')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get comment
     $comment = array('comment' => input::post('comment'));
     // Get table and column names
     $table = config::item('resources', 'core', $resource, 'table');
     $column = config::item('resources', 'core', $resource, 'column');
     $user = config::item('resources', 'core', $resource, 'user');
     // Get resource item
     $item = $this->db->query("SELECT `" . $column . "` " . ($user ? ', `' . $user . '` AS `user_id`' : '') . "\n\t\t\tFROM `:prefix:" . $table . "`\n\t\t\tWHERE `" . $column . "`=? LIMIT 1", array($itemID))->row();
     // Does resource exist?
     if (!$item) {
         return false;
     }
     // Save comment
     if (!$this->comments_model->saveComment(0, $comment, $resource, isset($item['user_id']) ? $item['user_id'] : 0, $itemID)) {
         if (!validate::getTotalErrors()) {
             view::setError(__('save_error', 'system'));
         }
         return false;
     }
     // Reset post values
     $_POST['comment'] = '';
     validate::resetRules();
     return true;
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:38,代码来源:comments.php

示例9: _saveMetaTags

 protected function _saveMetaTags($plugin, $tags)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     $rules = array();
     foreach ($tags as $keyword => $group) {
         foreach (config::item('languages', 'core', 'keywords') as $language) {
             $rules[$keyword . '_title_' . $language] = $rules[$keyword . '_description_' . $language] = $rules[$keyword . '_keywords_' . $language] = array('label' => '', 'rules' => array('is_string', 'trim', 'max_length' => 255));
         }
     }
     validate::setRules($rules);
     if (!validate::run()) {
         return false;
     }
     foreach ($tags as $keyword => $group) {
         $data = array();
         foreach (config::item('languages', 'core', 'keywords') as $language) {
             $data['meta_title_' . $language] = input::post($keyword . '_title_' . $language);
             $data['meta_description_' . $language] = input::post($keyword . '_description_' . $language);
             $data['meta_keywords_' . $language] = input::post($keyword . '_keywords_' . $language);
         }
         $this->metatags_model->saveMetaTags($plugin, $keyword, $data);
     }
     view::setInfo(__('meta_tags_saved', 'system_metatags'));
     router::redirect('cp/system/metatags/edit/' . $plugin);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:28,代码来源:metatags.php

示例10: _saveField

 protected function _saveField($plugin, $table, $categoryID, $fieldID, $fieldOld, $configs, $hidden)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Rules array
     $rules = array();
     // Data array
     $inputData = array('keyword', 'type', 'style', 'class', 'required', 'system', 'multilang');
     // Name
     foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) {
         $rules['name_' . $lang] = array('label' => __('name', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 255));
         $rules['vname_' . $lang] = array('label' => __('name_view', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
         $rules['sname_' . $lang] = array('label' => __('name_search', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
         $rules['validate_error_' . $lang] = array('label' => __('validate_error', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'max_length' => 255));
         $inputData[] = 'name_' . $lang;
         $inputData[] = 'vname_' . $lang;
         $inputData[] = 'sname_' . $lang;
         $inputData[] = 'validate_error_' . $lang;
     }
     // Keyword
     $rules['keyword'] = array('label' => __('keyword', 'system'), 'rules' => array('trim', 'required', 'alpha_dash', 'max_length' => 128, 'callback__is_unique_keyword' => array($plugin, $categoryID, $fieldID), 'callback__is_system_field' => array($fieldID ? $fieldOld['keyword'] : '', $fieldID ? $fieldOld['system'] : '')));
     // Type
     $rules['type'] = array('label' => __('field_type', 'system_fields'), 'rules' => array('required', 'callback__is_system_field' => array($fieldID ? $fieldOld['type'] : '', $fieldID ? $fieldOld['system'] : '')));
     // Style value
     $rules['style'] = array('label' => __('style', 'system_fields'), 'rules' => array('trim'));
     // Class value
     $rules['class'] = array('label' => __('class', 'system_fields'), 'rules' => array('trim'));
     // Required
     $rules['required'] = array('label' => __('required', 'system_fields'), 'rules' => array('intval'));
     // Regular expression
     $rules['validate'] = array('label' => __('validate', 'system_fields'), 'rules' => array('trim'));
     $inputData[] = 'validate';
     // Configuration array
     $inputConfig = array();
     foreach (array('custom', input::post('type')) as $conf) {
         if (isset($configs[$conf])) {
             foreach ($configs[$conf] as $option) {
                 $rules['config_' . $conf . '_' . $option['keyword']] = array('label' => utf8::strtolower($option['label']), 'rules' => isset($option['rules']) ? $option['rules'] : array());
                 $inputConfig[$option['keyword']] = 'config_' . $conf . '_' . $option['keyword'];
             }
         }
     }
     // Add items rules
     $items = array();
     $oldItems = $fieldID ? $fieldOld['items'] : array();
     if ($this->fields_model->isMultiValue(input::post('type'))) {
         $itemsPost = input::post('items');
         $sitemsPost = input::post('sitems');
         foreach (config::item('languages', 'core', 'keywords') as $languageID => $lang) {
             $orderID = 1;
             if (isset($itemsPost[$lang]) && is_array($itemsPost[$lang])) {
                 foreach ($itemsPost[$lang] as $itemID => $itemName) {
                     // Trim name
                     $itemName = utf8::trim($itemName);
                     // Assign item data
                     $items[$itemID]['order_id'] = $orderID;
                     $items[$itemID]['name_' . $lang] = $itemName;
                     $items[$itemID]['sname_' . $lang] = $sitemsPost[$lang][$itemID];
                     $orderID++;
                     // Add rule
                     $rules['items[' . $lang . '][' . $itemID . ']'] = array();
                     if ($itemName == '') {
                         validate::setRule('items', '', '');
                         validate::setFieldError('items', __('empty_item', 'system_fields') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''));
                     }
                 }
             }
         }
         if (!$items) {
             validate::setRule('items', '', '');
             validate::setFieldError('items', __('no_items', 'system_fields'));
         }
         view::assign(array('field' => array('items' => $items)));
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $fieldData = input::post($inputData);
     // Default data
     $fieldData['system'] = isset($hidden['system']) ? $hidden['system'] : 0;
     $fieldData['multilang'] = isset($hidden['multilang']) ? $hidden['multilang'] : 0;
     // Get config data
     $fieldData['config'] = array();
     foreach ($inputConfig as $key => $val) {
         $fieldData['config'][$key] = input::post($val);
     }
     // Set additional config data
     $fieldData['config']['html'] = input::post('html') ? 1 : 0;
     $fieldData['config']['in_search'] = input::post('in_search') ? 1 : 0;
     $fieldData['config']['in_search_advanced'] = input::post('in_search_advanced') ? 1 : 0;
     if ($fieldData['config']['in_search'] || $fieldData['config']['in_search_advanced']) {
         $fieldData['config']['search_options'] = input::post('search_options') ? input::post('search_options') : '';
     }
     if (input::post('type') == 'checkbox' || input::post('search_options') == 'multiple') {
//.........这里部分代码省略.........
开发者ID:soremi,项目名称:tutornavi,代码行数:101,代码来源:system.php

示例11: _saveType

 protected function _saveType($typeID, $type, $fields)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Rules array
     $rules = array();
     // Input data array
     $input = array('keyword', 'field_name_1', 'field_name_2');
     // Name field
     foreach (config::item('languages', 'core', 'keywords') as $languageID => $language) {
         $rules['name_' . $language] = array('label' => __('name', 'system') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 128));
         $input[] = 'name_' . $language;
     }
     // Keyword field
     $rules['keyword'] = array('label' => __('keyword', 'system'), 'rules' => array('required', 'max_length' => 32, 'alpha_dash', 'strtolower', 'callback__is_unique_keyword' => $typeID));
     // Is this an existing type?
     if ($typeID) {
         $rules['field_name_1'] = array('label' => __('type_fields_name', 'users_types'), 'rules' => array('max_length' => 128, 'callback__is_valid_field_name' => array('field_name_1', $fields)));
         $rules['field_name_2'] = array('label' => __('type_fields_name', 'users_types'), 'rules' => array('max_length' => 128, 'callback__is_valid_field_name' => array('field_name_2', $fields)));
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get post data
     $data = input::post($input);
     // Save user type
     if (!($newTypeID = $this->users_types_model->saveType($typeID, $data))) {
         if ($typeID) {
             view::setError(__('db_no_rename', 'system_fields'));
         } else {
             view::setError(__('db_no_create', 'system_fields'));
         }
         return false;
     }
     // Is this an existing type?
     if ($typeID) {
         $fields = config::item('usertypes', 'core', 'fields', $typeID);
         if (($data['field_name_1'] || $data['field_name_2']) && ($fields[1] != $data['field_name_1'] || $fields[2] != $data['field_name_2'])) {
             $this->users_types_model->updateNames($typeID, $data['field_name_1'], $data['field_name_2']);
         }
     }
     // Success
     view::setInfo(__('type_saved', 'users_types'));
     router::redirect('cp/users/types/edit/' . $newTypeID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:50,代码来源:types.php

示例12: _savePermissions

 protected function _savePermissions($ids, $plugin, $permissions)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = array();
     foreach ($permissions as $groupID => $group) {
         foreach (array('cp', 'ca') as $section) {
             if (isset($permissions[$groupID][$section])) {
                 foreach ($permissions[$groupID][$section] as $permission) {
                     $rules[$permission['keyword'] . '_' . $groupID] = array('label' => $permission['name'], 'rules' => '');
                 }
             }
         }
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Create permissions array
     $data = $orderID = array();
     foreach ($permissions as $groupID => $group) {
         foreach (array('cp', 'ca') as $section) {
             if (isset($permissions[$groupID][$section])) {
                 foreach ($permissions[$groupID][$section] as $permission) {
                     $value = input::post($permission['keyword'] . '_' . $groupID);
                     if ($permission['type'] == 'checkbox') {
                         $value = $value ? implode(',', $value) : '';
                     } elseif ($permission['type'] == 'boolean' || $permission['type'] == 'number') {
                         $value = $value ? (int) $value : 0;
                     }
                     $data[$permission['keyword']] = $value;
                     if (config::item('devmode', 'system') == 2) {
                         $orderID[$permission['keyword']] = (int) input::post($permission['keyword'] . '___order');
                     }
                 }
             }
         }
         // Save user group permissions
         if (!$this->users_groups_model->savePermissions($groupID, $plugin, $data, $orderID)) {
             view::setError(__('save_error', 'system'));
             return false;
         }
     }
     // Successs
     view::setInfo(__('permissions_saved', 'users_permissions'));
     router::redirect('cp/users/groups/permissions/' . $plugin . '/' . $ids);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:52,代码来源:groups.php

示例13: _saveSubject

 protected function _saveSubject($subjectID)
 {
     // Check if demo mode is enabled
     if (input::demo()) {
         return false;
     }
     // Create rules
     $rules = $input = array();
     // Get subject data
     $subjectData = array();
     foreach (config::item('languages', 'core', 'keywords') as $languageID => $language) {
         $rules['name_' . $language] = array('label' => __('name', 'system') . (count(config::item('languages', 'core', 'keywords')) > 1 ? ' [' . config::item('languages', 'core', 'names', $languageID) . ']' : ''), 'rules' => array('trim', 'required', 'max_length' => 255));
         $input[] = 'name_' . $language;
     }
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Get subject data
     $subject = input::post($input);
     $subject['active'] = input::post('active') ? 1 : 0;
     // Save subject
     if (!($subjectID = $this->reports_subjects_model->saveSubject($subjectID, $subject))) {
         view::setError(__('save_error', 'system'));
         return false;
     }
     // Success
     view::setInfo(__('subject_saved', 'reports_subjects'));
     router::redirect('cp/content/reports/subjects/edit/' . $subjectID);
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:32,代码来源:subjects.php

示例14: _uploadPicture

 protected function _uploadPicture()
 {
     // Create rules
     $rules = array('file' => array('label' => __('file_select', 'system_files'), 'rules' => array('required_file' => 'file')));
     // Assign rules
     validate::setRules($rules);
     // Validate form values
     if (!validate::run()) {
         return false;
     }
     // Thumbnails config
     $thumbs = array(array('suffix' => 'x'), array('dimensions' => config::item('picture_dimensions', 'users'), 'method' => 'preserve', 'suffix' => ''), array('dimensions' => config::item('picture_dimensions_p', 'users'), 'method' => 'crop', 'suffix' => 'p'), array('dimensions' => config::item('picture_dimensions_l', 'users'), 'method' => 'crop', 'suffix' => 'l'), array('dimensions' => config::item('picture_dimensions_t', 'users'), 'method' => 'crop', 'suffix' => 't'));
     // Upload picture
     if (!($fileID = $this->storage_model->upload('user', session::item('user_id'), 'file', 'jpg|jpeg|gif|png', config::item('picture_max_size', 'users'), config::item('picture_dimensions_max', 'users'), $thumbs))) {
         if (input::isAjaxRequest()) {
             view::ajaxError(config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
         } else {
             validate::setFieldError('file', config::item('devmode', 'system') ? $this->storage_model->getError() : __('file_upload_error', 'system_files'));
         }
         return false;
     }
     // Delete old picture if it exists
     if (session::item('picture_id')) {
         // Delete picture
         $this->users_model->deletePicture(session::item('user_id'), session::item('picture_id'), false);
     }
     // Save new picture ID
     if (!$this->users_model->savePicture(session::item('user_id'), $fileID)) {
         if (input::isAjaxRequest()) {
             view::ajaxError(__('save_error', 'system'));
         } else {
             validate::setFieldError('file', __('save_error', 'system'));
             return false;
         }
     }
     // Was this an ajax request?
     if (input::isAjaxRequest()) {
         view::ajaxResponse(array('redirect' => html_helper::siteURL(session::item('slug'))));
     }
     // Success
     view::setInfo(__('picture_uploaded', 'users_picture'));
     router::redirect(session::item('slug'));
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:43,代码来源:profile.php

示例15: _saveEmail

 protected function _saveEmail()
 {
     // Creat rules
     $rules = array('email' => array('label' => __('email_new', 'users'), 'rules' => array('trim', 'required', 'max_length' => 255, 'valid_email', 'callback__is_unique_email')), 'password' => array('label' => __('password_current', 'users'), 'rules' => array('trim', 'required', 'min_length' => 4, 'max_length' => 128, 'callback__is_valid_password')));
     // Assign rules
     validate::setRules($rules);
     // Validate fields
     if (!validate::run()) {
         return false;
     }
     // Do we need to verify email address?
     if (config::item('signup_email_verify', 'users')) {
         // Load requests model
         loader::model('system/requests');
         // Is this a recent request?
         if (config::item('signup_delay', 'users') != -1 && $this->requests_model->isRecentRequest('newemail', session::item('user_id'), 0, config::item('signup_delay', 'users'))) {
             // Success
             view::setError(__('email_change_recent', 'users'));
             return false;
         }
         // Load email library
         loader::library('email');
         // Save signup request
         $hash = $this->requests_model->saveRequest('newemail', session::item('user_id'), 0, input::post('email'));
         $tags = session::section('session');
         $tags['security_hash'] = $hash;
         $tags['activation_link'] = config::siteURL('users/settings/newemail/' . $hash);
         // Send activation email
         $this->email->sendTemplate('users_account_confirm', input::post('email'), $tags, session::item('language_id'));
         // Success
         view::setInfo(__('email_confirm', 'users'));
     } else {
         // Save user
         if (!$this->users_model->saveEmail(session::item('user_id'), input::post('email'))) {
             view::setError(__('save_error', 'system'));
             return false;
         }
         // Success
         view::setInfo(__('email_saved', 'users'));
     }
     router::redirect('users/settings');
 }
开发者ID:soremi,项目名称:tutornavi,代码行数:42,代码来源:settings.php


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