好!欢迎访问迷津渡口 现在时间是: 天气 °C ~ °C

迷津渡口

越感到迷惑 越接近真理

emlog MVC解构21--控制器Controller之Sort_Controller

Sort_Controller控制器用于查看分类文章。

只有一个方法display($params):$params为Dispatcher传出来的正则表达式$matches。

function display($params) {
    // 建立日志模型
    $Log_Model = new Log_Model();
    // 建立缓存
    $CACHE = Cache::getInstance();
    // 获取配置缓存
    $options_cache = Option::getAll();
    // 将配置缓存里每个键名转换成变量,键值为相应的变量值
    extract($options_cache);
    
    // 若查询包含页面,则获取页码,默认为第一页
    $page = isset($params[4]) && $params[4] == 'page' ? abs(intval($params[5])) : 1;
    
    // 定义分类ID变量
    $sortid = '';
    // 访问分类页面时,$params[1]='sort'
    // 没有别名时$params[2]为分类ID,有别名且开启别名时$params[2]为别名字符串
    if (!empty($params[2])) {
        if (is_numeric($params[2])) { // 参数为数字时,直接获取分类ID
            $sortid = intval($params[2]);
        } else { // 参数为别名字符串时
            // 获取分类缓存
            $sort_cache = $CACHE->readCache('sort');
            
            /**$sort_cache的结构为:
             * array( $sid0 => // 分类ID
             *         array(
             *             'lognum' => 分类包含的日志数量,
             *             'sortname' => 分类名,
             *             'description' => 分类描述,
	     *             'alias' => 分类别名,
	     *             'sid' => 分类ID,
             *             'taxis' => 分类排列序号,
	     *             'pid' => 父分类ID,
	     *             'template' => 分类页面模板,
	     *             'children' => 子分类ID,没有则为空数组
	     *         ),
	     *         $sid1 => 
	     *           array(...),
	     *         ...
	     * );
	     **/                 
            foreach ($sort_cache as $key => $value) {
                $alias = addslashes(urldecode(trim($params[2])));
                if (array_search($alias, $value, true)){ // 搜索数组,获取分类ID
                    $sortid = $key;
                    break;
                }
            }
        }
    }
    
    // 定义访问地址
    $pageurl = '';
    
    // 获取分类缓存
    $sort_cache = $CACHE->readCache('sort');
    // 分类缓存不存在此分类ID,输出404页面
    if (!isset($sort_cache[$sortid])) {
        show_404_page();
    }
    // 分类缓存存在此分类ID,获取分类信息数组
    $sort = $sort_cache[$sortid];
    // 获取分类名
    $sortName = $sort['sortname'];
    // 设置分类页面站点标题为分类名-站点浏览器标题
    $site_title = $sortName . ' - ' . $site_title;
    // 设置分类页面站点描述为分类描述
    if (!empty($sort_cache[$sortid]['description'])) {
        $site_description = $sort_cache[$sortid]['description'];
    }
    // 分类本身是子分类或者本身没有子分类
    if ($sort['pid'] != 0 || empty($sort['children'])) {
        // 数据库查询仅需获取分类本身数据
        $sqlSegment = "and sortid=$sortid";
    } else { // 分类是主分类且有子分类
        // 分类本身及其子分类ID放在一个数组
        $sortids = array_merge(array($sortid), $sort['children']);
        // 数据库查询获取分类本身及其子分类数据
        $sqlSegment = "and sortid in (" . implode(',', $sortids) . ")";
    }
    // 分类置顶排前面,新发表的排前面
    $sqlSegment .=  " order by sortop desc, date desc";
    // 获取分类列表将获取已发布的文章数
    $lognum = $Log_Model->getLogNum('n', $sqlSegment);
    // $index_lognum由Option获取的变量,列表单页的日志数量
    // 获得列表总页数
    $total_pages = ceil($lognum / $index_lognum);
    if ($page > $total_pages) { // 页码超过总页数
        // 页码设置为最后一页
        $page = $total_pages;
    }
    // 利用Url工具类方法获取分类链接
    $pageurl .= Url::sort($sortid, 'page');
    
    // 利用Log_Model方法获取当页日志列表
    $logs = $Log_Model->getLogsForHome($sqlSegment, $page, $index_lognum);
    // 利用工具函数获取输出列表页底部页码导航的字符串
    $page_url = pagination($lognum, $index_lognum, $page, $pageurl);
    
    // 获取分类页面模板,若有设置则为自定义模板,否则默认为log_list.php
    $template = !empty($sort['template']) && file_exists(TEMPLATE_PATH . $sort['template'] . '.php') ? $sort['template'] : 'log_list';
    
    // View调用前台模板里面的header.php和$template.php,默认为log_list.php
    include View::getView('header');
    include View::getView($template);
}


点赞1
   支持一下
挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
 点赞
 签到
 表情
 图片
 代码
提交评论

清空信息
关闭评论
mandydugan
 mandydugan 约 5 小时前回复
#109
<a href="http://www.flushnhunt.com/usc-snapback-hat-hath">usc snapback hat</a> <a href="http://www.evelpa.com/nike-lunar-force-1-noir-chaussuresh">nike lunar force 1 noir</a> <a href="http://www.taaliminfos.com/nike-zoom-structure-20-bianca-viola-scarpel">nike zoom structure 20 bianca viola</a> <a href="http://www.cacikvideo.com/air-jordan-retro-1-pink-gold-shoesj">air jordan retro 1 pink gold</a> <a href="http://www.grossavind.com/nike-kobe-10-bl%C3%A5-appelsin-skoi">nike kobe 10 bl氓 appelsin</a> <a href="http://www.boltsfans.com/adidas-zx-700-cielo-blu-viola-scarpeq">adidas zx 700 cielo blu viola</a>
mandydugan http://www.mandydugan.com/
culdesacmag
 culdesacmag 2019-03-18 06:00回复
#108
<a href="http://www.cardiachits.com/nike-lunarelite-sky-hi-gr%C3%B8n-skol">nike lunarelite sky hi gr酶n</a> <a href="http://www.zestchannel.com/curry-one-noir-chaussuresq">curry one noir</a> <a href="http://www.eczacinim.com/nike-air-max-95-femmes-or-noir-chaussuresl">nike air max 95 femmes or noir</a> <a href="http://www.chilangorails.com/nike-free-inneva-woven-rot-schuhei">nike free inneva woven rot</a> <a href="http://www.mariusen.com/dam%C3%A4nner-nike-air-max-tailwind-5-gelb-schuheh">dam盲nner nike air max tailwind 5 gelb</a> <a href="http://www.brittonoilco.com/nike-roshe-run-hyperfuse-svart-cool-gr%C3%A5-obuvj">nike roshe run hyperfuse svart cool gr氓</a>
culdesacmag http://www.culdesacmag.com/
themenfinder
 themenfinder 2019-03-18 00:46回复
#107
<a href="http://www.alexisellen.com/nike-limited-tyler-lockett-jersey-16-nfl-seattle-seahawks-salute-to-service-mens-black-gold-nflx">nike limited tyler lockett jersey 16 nfl seattle seahawks salute to service mens black gold</a> <a href="http://www.benitoitegems.com/dodgers-blank-light-blue-cooperstown-stitched-mlb-jersey-nflw">dodgers blank light blue cooperstown stitched mlb jersey</a> <a href="http://www.hepalmak.com/nike-dunk-skinny-hvid-chaussuresa">nike dunk skinny hvid</a> <a href="http://www.ibrahimoner.com/mennns-nike-dunk-gul-bl%C3%A5-butya">mennns nike dunk gul bl氓</a> <a href="http://www.jindorescue.com/hommes-asics-gel-noosa-tri-8-jaune-gris-butyc">hommes asics gel noosa tri 8 jaune gris</a> <a href="http://www.melekmelodifm.com/kobe-vi-all-svart-obuvf">kobe vi all svart</a>
themenfinder http://www.themenfinder.com/
coralbayconsulting
 coralbayconsulting 2019-03-17 19:24回复
#106
<a href="http://www.historicsheds.net/nike-air-max-90-essential-midnight-fl%C3%A5den-schuhed">nike air max 90 essential midnight fl氓den</a> <a href="http://www.hochschulschrift.net/jordan-fusion-12-svart-and-hvit-butye">jordan fusion 12 svart and hvit</a> <a href="http://www.hotvape.net/nike-air-max-2014-orange-herre-obuvd">nike air max 2014 orange herre</a> <a href="http://www.hungate.net/air-max-1-og-rot-2017-obuvg">air max 1 og rot 2017</a> <a href="http://www.idreamtan.net/nike-magista-obra-ag-with-acc-cleats-blau-wei%C3%9F-schwarz-schuhef">nike magista obra ag with acc cleats blau wei脽 schwarz</a> <a href="http://www.ikkunatehdas.net/nike-free-3.0-flyknit-dark-obsidian-hvit-gul-obuve">nike free 3.0 flyknit dark obsidian hvit gul</a>
coralbayconsulting http://www.coralbayconsulting.net/
ladivorcecpa
 ladivorcecpa 2019-03-17 19:15回复
#105
<a href="http://www.luftfotosepp.com/air-jordan-1-r%C3%B8d-and-gr%C3%B8n-butyd">air jordan 1 r酶d and gr酶n</a> <a href="http://www.musicbreeds.com/nike-air-max-95-stussy-s%C3%B8lv-orange-obuvg">nike air max 95 stussy s酶lv orange</a> <a href="http://www.pritoi.com/air-jordan-retro-14-himmelen-bl%C3%A5-royal-bl%C3%A5-kurpesa">air jordan retro 14 himmelen bl氓 royal bl氓</a> <a href="http://www.smokeclothes.com/air-jordan-29-wei%C3%9F-braun-kurpesf">air jordan 29 wei脽 braun</a> <a href="http://www.tekniknetto.com/sort-ralph-lauren-polo-pony-fleece-esp-m%C3%A6nd-big-jacket-poloz">sort ralph lauren polo pony fleece esp m忙nd big jacket</a> <a href="http://www.vspeyedoctors.com/air-jordan-super-fly-iv-blu-bianca-scarpec">air jordan super fly iv blu bianca</a>
ladivorcecpa http://www.ladivorcecpa.com/
powersellingmom
 powersellingmom 2019-03-17 17:57回复
#104
<a href="http://www.caninewingman.net/asics-gel-noosa-tri-9-bianca-electric-blu-mint-scarpec">asics gel noosa tri 9 bianca electric blu mint</a> <a href="http://www.caqueta.net/nike-air-force-1-low-gelb-lila-chaussurese">nike air force 1 low gelb lila</a> <a href="http://www.clubcombo.net/air-jordan-retro-8-alle-gr%C3%A5-butya">air jordan retro 8 alle gr氓</a> <a href="http://www.cometwifi.net/nike-free-trainer-5.0-nkg-naranja-marr%C3%B3n-schuhea">nike free trainer 5.0 nkg naranja marr贸n</a> <a href="http://www.communityfm.net/nike-sb-stefan-janoski-max-rosa-lila-schuheb">nike sb stefan janoski max rosa lila</a> <a href="http://www.coralbayconsulting.net/nike-air-presto-rosso-nero-bianca-butyd">nike air presto rosso nero bianca</a>
powersellingmom http://www.powersellingmom.net/
xmrujo
 xmrujo 2019-03-16 09:40回复
#103
<a href="http://www.adanastarpen.com/mujeres-nike-zoom-pegasus-32-blanco-p%C3%BArpura-zapatosk">mujeres nike zoom pegasus 32 blanco p煤rpura</a> <a href="http://www.actconfident.com/nike-lunarglide-7-mujeres-rosado-verde-zapatosp">nike lunarglide 7 mujeres rosado verde</a> <a href="http://www.erzurumihl.com/north-face-down-jacket-parka-northfaceh">north face down jacket parka</a> <a href="http://www.candctowingil.com/nike-lebron-13-dam%C3%A4nner-silber-gelb-schuhej">nike lebron 13 dam盲nner silber gelb</a> <a href="http://www.onlysidekick.com/nike-air-huarache-kvinders-gr%C3%A5-r%C3%B8d-skoh">nike air huarache kvinders gr氓 r酶d</a> <a href="http://www.rmmassage.com/nike-air-max-90-femmes-bleu-ciel-oranger-chaussuresh">nike air max 90 femmes bleu ciel oranger</a>
xmrujo http://www.xmrujo.com/
awassessment
 awassessment 2019-03-15 13:06回复
#102
<a href="http://www.imfunniest.com/nike-roshe-run-m%C3%A6nd-bl%C3%A5-gr%C3%B8n-skoh">nike roshe run m忙nd bl氓 gr酶n</a> <a href="http://www.emissariesbc.com/adidas-prossoator-instinct-sg-scarpei">adidas prossoator instinct sg</a> <a href="http://www.partnersspa.com/nike-air-max-2018-femminile-nero-rosa-scarpej">nike air max 2018 femminile nero rosa</a> <a href="http://www.antirealtor.com/minnesota-vikings-adrian-peterson-jersey-nflh">minnesota vikings adrian peterson jersey</a> <a href="http://www.jkjuiceplus.com/coach-gray-crossbody-bag-coachh">coach gray crossbody bag</a> <a href="http://www.bkindvending.com/nike-air-max-nero-and-bianca-maschio-scarpei">nike air max nero and bianca maschio</a>
awassessment http://www.awassessment.com/
meetingxs
 meetingxs 2019-03-15 06:45回复
#101
<a href="http://www.nomorbogor.com/asics-gel-noosa-tri-10-menns-s%C3%B8lv-sneakerb">asics gel noosa tri 10 menns s酶lv</a> <a href="http://www.sozihoster.com/nike-flyknit-lunar-1-atomic-pink-kaufen-skod">nike flyknit lunar 1 atomic pink kaufen</a> <a href="http://www.allbidder.com/christian-louboutin-outlet-houston-texas-louboutine">christian louboutin outlet houston texas</a> <a href="http://www.yrlogoworks.com/pandora-princess-ring-stack-pandorar">pandora princess ring stack</a> <a href="http://www.sateambeast.com/ray-ban-rb4057-sunglasses-womens-sunglassesf">ray ban rb4057 sunglasses womens</a> <a href="http://www.druckberg.com/prada-pink-sunglasses-pradar">prada pink sunglasses</a>
[url=http://www.meetingxs.com/]meetingxs[/url]
dinerwareoc
 dinerwareoc 2019-03-15 04:16回复
#100
<a href="http://www.varsitystance.com/new-balance-996-womens-yellow-silver-trainersce">new balance 996 womens yellow silver</a> <a href="http://www.azuraonline.com/ray-ban-clubmaster-reading-glasses-sunglassesr">ray ban clubmaster reading glasses</a> <a href="http://www.twiggyallure.com/mackage-vane-coat-sale-mackager">mackage vane coat sale</a> <a href="http://www.benbageltours.com/nike-air-max-90-womens-nordstrom-sneakere">nike air max 90 womens nordstrom</a> <a href="http://www.msupers.com/nike-air-vapormax-mens-red-white-footc">nike air vapormax mens red white</a> <a href="http://www.johnklymshyn.com/nike-air-max-97-schwarz-wei%C3%9F-skox">nike air max 97 schwarz wei脽</a>
dinerwareoc http://www.dinerwareoc.com/
顶部留言底部
 00:00/00:00
我想和你虚度时光 - 花房姑娘(9)
  1. 我想和你虚度时光
  2. 花房姑娘
  3. 恋恋风尘
  4. 我喜爱一切不彻底的事物
  5. 我的心里是满的
  6. Long Way
  7. 给少年的歌
  8. 晴日共剪窗
  9. 天上的月你的脸