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


PHP Redirect::add方法代码示例

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


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

示例1: postProcess

 public function postProcess()
 {
     $id_shops = array();
     if (Tools::isSubmit('mass_csv_form_submit')) {
         if (Shop::getContext() == Shop::CONTEXT_ALL) {
             $shops = Shop::getShops();
             if (!empty($shops)) {
                 foreach ($shops as $s) {
                     $id_shops[] = $s['id_shop'];
                 }
             }
         } elseif (Shop::getContext() == Shop::CONTEXT_GROUP) {
             $shopid = Shop::getContextShopGroupID(true);
             $shops = ShopGroup::getShopsFromGroup($shopid);
             if (!empty($shops)) {
                 foreach ($shops as $s) {
                     $id_shops[] = $s['id_shop'];
                 }
             }
         }
         if (empty($id_shops)) {
             $id_shops[] = Shop::getContextShopID();
         }
         $id_shops = array_unique($id_shops);
         if (is_uploaded_file($_FILES['csv_file']['tmp_name'])) {
             $mimes = array('application/vnd.ms-excel', 'text/plain', 'text/csv', 'text/tsv');
             if (!in_array($_FILES['csv_file']['type'], $mimes)) {
                 $this->errors[] = Tools::displayError($this->l('Error : Problem with file upload. Please retry or check your file.'));
                 return false;
             }
             if (move_uploaded_file($_FILES['csv_file']['tmp_name'], $this->mod->cache_dir . $_FILES['csv_file']['name'])) {
                 $old_file_name = $_FILES['csv_file']['name'];
                 $csv_content = Tools::file_get_contents($this->mod->cache_dir . $old_file_name);
                 $array = $this->csvToArray($csv_content);
                 if (empty($array)) {
                     $this->errors[] = Tools::displayError($this->l('Error : Problem with file upload. Please retry or check your file.'));
                     parent::postProcess();
                     return false;
                 }
                 foreach ($array as $value) {
                     if (!empty($value[0])) {
                         $new = !empty($value[1]) ? trim($value[1]) : '/';
                         $type = !empty($value[2]) ? trim($value[2]) : '301';
                         $regex = !empty($value[3]) ? (int) $value[3] : 0;
                         $redirect = new Redirect();
                         $redirect->old = trim($value[0]);
                         $redirect->new = $new;
                         $redirect->type = $type;
                         $redirect->regex = (bool) $regex;
                         $redirect->active = true;
                         $redirect->add();
                         /*foreach ($id_shops as $v) {
                               $db->execute('INSERT INTO `'._DB_PREFIX_.'redirect_shop` (`id_redirect_shop`,`id_redirect`, `id_shop`) VALUES (NULL,'.(int)$redirect->id.','.(int)$v.')');
                           }*/
                     }
                 }
             }
             Tools::redirectAdmin(self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminRedirect') . '&conf=4');
         }
     }
     parent::postProcess();
 }
开发者ID:acreno,项目名称:pm-ps,代码行数:62,代码来源:AdminRedirectController.php

示例2: insertRedirects

 public function insertRedirects($redirects, $force_active = false)
 {
     $db = Db::getInstance();
     $active = (bool) ($force_active === true || (bool) Configuration::get('MGRT_AUTOACTIVE') === true);
     foreach ($redirects as $redirect) {
         if (empty($redirect['shops'])) {
             continue;
         }
         // Checking potential conflicts
         foreach ($redirect['shops'] as $id_shop) {
             $old = '/' . ltrim($redirect['old'], '/');
             $new = isset($redirect['new']) ? '/' . ltrim($redirect['new'], '/') : '/';
             $this->checkConflict($old, $id_shop);
             $id_redirect = $db->getValue('SELECT * FROM ' . _DB_PREFIX_ . 'redirect r WHERE r.regex = 0 AND r.old = "' . pSQL($old) . '" AND r.new = "' . pSQL($new) . '"');
             //Making new if don't already exist
             if (empty($id_redirect)) {
                 // Let's log it
                 $obj = new Redirect();
                 $obj->old = $old;
                 $obj->new = $new;
                 $obj->type = '301';
                 $obj->regex = false;
                 $obj->active = $active;
                 $obj->add();
                 $id_redirect = $obj->id;
             }
             $db->execute('INSERT INTO `' . _DB_PREFIX_ . 'redirect_shop` (`id_redirect_shop`, `id_redirect`, `id_shop`) VALUES (NULL, ' . (int) $id_redirect . ', ' . (int) $id_shop . ')');
         }
     }
 }
开发者ID:acreno,项目名称:pm-ps,代码行数:30,代码来源:magicredirect.php


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