Example #1
0
 /**
  * 路由到另外的页面
  *
  * @param object  $controller       当前跳转的控制器
  * @param string  $url              你想路由到的页面的 URL
  * @param boolean $rememberCurrent  是否记录当前页面的 URL,方便你之后用 jumpBack() 回到这个页面, 比如现在你需要让用户去登陆,登陆完之后你希望能返回当前页面
  *
  * */
 public static function reRoute($controller, $url, $rememberCurrent = false)
 {
     global $f3;
     if ($rememberCurrent) {
         self::setJumpBackUrl(Route::getFullURL());
     }
     // reroute 之前调用 afterRoute() 方法
     if (isset($controller) && is_object($controller) && method_exists($controller, 'afterRoute')) {
         $controller->afterRoute($f3);
     }
     // 如果 URL 不是绝对地址,我们生成绝对地址(静态化的时候保持地址格式一致)
     if (self::$isMakeStaticUrl && !Route::isUrlAbsolute($url) && false === strpos($url, '?')) {
         $url = Route::makeUrl($url, null, false, true);
     }
     if (Route::$enableSessionIdUrl) {
         $url = Route::addParam($url, array(session_name() => session_id()));
     }
     $f3->reroute($url);
 }
Example #2
0
    /**
     * 输出 sitemapIndex 文件
     */
    public function outputSiteMapXml($f3, $fileName)
    {
        global $smarty;
        //缓存 60 分钟
        enableSmartyCache(true, 3600, \Smarty::CACHING_LIFETIME_CURRENT);
        $smartyCacheId = 'Api|' . md5(__NAMESPACE__ . '\\' . __CLASS__ . '\\' . __METHOD__);
        // 判断是否有缓存
        if ($smarty->isCached('empty.tpl', $smartyCacheId)) {
            goto out_display;
        }
        // sitemap 列表
        $siteMapFileList = '';
        // 当前时间
        $currentTime = time();
        /***************** 生成 /Goods/View 列表 *******************/
        // 查询商品数量,决定分页有多少页
        $currentThemeInstance = ThemeHelper::getCurrentSystemThemeInstance();
        $totalGoodsCount = SearchHelper::count(SearchHelper::Module_Goods, array(array(QueryBuilder::buildGoodsFilterForSystem($currentThemeInstance->getGoodsFilterSystemArray(), 'g'))));
        $pageCount = ceil($totalGoodsCount / $this->pageSize);
        // 取得当前的目录路径
        $currentUrl = RouteHelper::getFullURL();
        $currentUrl = substr($currentUrl, 0, strrpos($currentUrl, $fileName));
        // 生成 goods 页面索引
        for ($index = 0; $index < $pageCount; $index++) {
            $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'GoodsView_' . $currentTime . '_' . $index . '.xml</loc></sitemap>';
        }
        /***************** 生成 /Goods/Search 列表 *******************/
        // 生成 search 页面索引
        $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'GoodsSearch_' . $currentTime . '_0.xml</loc></sitemap>';
        /***************** 生成 /Article/View 列表 *******************/
        // 查询商品数量,决定分页有多少页
        $totalArticleCount = SearchHelper::count(SearchHelper::Module_Article, QueryBuilder::buildSearchParamArray(array('a.is_open' => 1)));
        $pageCount = ceil($totalArticleCount / $this->pageSize);
        // 生成 Article 页面索引
        for ($index = 0; $index < $pageCount; $index++) {
            $siteMapFileList .= '<sitemap><loc>' . $currentUrl . 'ArticleView_' . $currentTime . '_' . $index . '.xml</loc></sitemap>';
        }
        $apiXml = <<<XML
<?xml version="1.0" encoding="utf-8" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{$siteMapFileList}
</sitemapindex>
XML;
        $smarty->assign('outputContent', $apiXml);
        out_display:
        header('Content-Type:text/xml;charset=utf-8');
        header("Cache-Control: no-cache, must-revalidate");
        // HTTP/1.1 //查询信息
        $smarty->display('empty.tpl', $smartyCacheId);
    }
Example #3
0
        BzfDebug::enableDebug();
        // 开启 Smarty Web Log
        BzfDebug::enableSmartyWebLog();
    }
} else {
    /*** 错误处理,如果网站出现错误,我简单的把用户定位到 首页 ***/
    $f3->set('ONERROR', function ($f3) {
        /**
         * Information about the last HTTP error that occurred.
         * ERROR.code is the HTTP status code.
         * ERROR.title contains a brief description of the error.
         * ERROR.text provides greater detail. For HTTP 500 errors, use ERROR.trace to retrieve the stack trace.
         */
        $code = $f3->get('ERROR.code');
        if (404 == intval($code)) {
            RouteHelper::reRoute(null, '/Error/E404?url=' . urlencode(RouteHelper::getFullURL()));
        } else {
            RouteHelper::reRoute(null, '/');
        }
    });
}
// ---------------------------------------- 4. 加载显示主题 -----------------------------------
// 为 Manage 设置网站的 WebRootBase,这样在 Manage 中就可以对相应网站做操作
$systemUrlBase = ManageThemePlugin::getSystemUrlBase(PluginHelper::SYSTEM_SHOP);
if (empty($systemUrlBase) || $systemUrlBase['base'] != $f3->get('sysConfig[webroot_url_prefix]')) {
    ManageThemePlugin::saveSystemUrlBase(PluginHelper::SYSTEM_SHOP, '商城', '棒主妇商城', $f3->get('sysConfig[webroot_url_prefix]'));
}
$themeIntance = ThemeHelper::loadSystemTheme(ThemeHelper::SYSTEM_SHOP_THEME);
if (!$themeIntance) {
    die('没有正确设置 ' . ThemeHelper::SYSTEM_SHOP_THEME . ' 主题');
}