7. 翻页的实现

1. pylon的翻页实现首先需要smarty模板引擎的支持:(不会Smarty的请点这里)

首先在src/apps/fnt/assembly.php系统装配器中添加Smarty前端展示的支持: 

<?php
class NavSysAssembly
{/*{{{*/
    static public function setup($cacheSvc=null)
    {/*{{{*/
        CommonAssemply::setup($cacheSvc);
        //        XAop::pos(XAop::LOGIC)->append_by_dismatch_name("login",  new QucAuthorization());         XAop::pos(XAop::LOGIC)->append_by_match_name(".*", new AutoCommit());

        XAop::pos(XAop::TPL  )->append_by_match_name(".*", new NavView());
        if(Conf::ENV!='dev'){
            XAop::pos(XAop::ERROR)->append_by_match_name(".*", 
new  NavUserInputErrorPoc());
            XAop::pos(XAop::ROOT_ERROR)->append_by_match_name(".*", 
new NavErrorPoc());
        }
        XAop::pos(XAop::TPL  )->append_by_match_name(".*", 
new FrontAutoSmartyView()); //添加这句对Smarty进行支持     }/*}}}*/
}/*}}}*/
?>

然后在/src/apps/fnt/actions/intercept.php中定义FrontAutoSmartyView类:

class FrontAutoSmartyView implements XScopeInterceptor {/*{{{*/
    static function viewProc($tpl,$vars,$request,$xcontext)
    {/*{{{*/
        if($vars == "STRUCT")
        {
            $xcontext->_view = "front_wrapper.html";
            if($tpl == "AUTO")
            {
                $xcontext->_autoview = $xcontext->_action  . ".html";
            }
            else
            {
                $xcontext->_autoview = $tpl;
            }
        }
        else
        {
            if($tpl == "AUTO")
            {
                $xcontext->_view= $xcontext->_action  . ".html";
            }
            else
            {
                $xcontext->_view= $tpl;
            }
        }
    }/*}}}*/
    public function _before($request,$xcontext)
    {/*{{{*/
        $smartyRoot  = Conf::PRJ_ROOT."/tmp/smarty/front";
        $appTplPath  = Conf::PRJ_ROOT . "/" . Conf::APP_TPL_PATH;
        $baseTplPath = Conf::PRJ_ROOT . "/" . Conf::BASE_TPL_PATH;
        $tpldirs = Conf::PRJ_ROOT . "/src/web_inf/tpls/front/" ;
        XTools::regRenderer( new SmartyRenderer($smartyRoot,$tpldirs));
        self::viewProc($xcontext->_view,$xcontext->_view_vars,$request,$xcontext);
        $xcontext->theme = new Theme($appTplPath,$baseTplPath);
    }/*}}}*/
    public function _after($request,$xcontext)
    {/*{{{*/
    }/*}}}*/
}/*}}}*/

2. 翻页的实现

(1)action中需要的修改:

class Action_index extends ActionBase
{
    public function _run($request,$xcontext)
    {
        $request->pageObj->pageRows = 3;	//设置每页显示的行数         $dq = Dquery::ins();
        $info = $dq->list_msg($request->pageObj);//将翻页对象当做额外的参数传递给查询语句         $xcontext->info = $info;
        return XNext::useTpl('index.html');
    }
}
?>

(2)html中的修改:
在正常输出页面后添加语句:

{include_tpl file="page_part.html"}

page_part.html就是翻页的模板文件。

(3)添加page_part.html

在/src/web_inf/tpls/下添加page_part.html文件;

{if !$_uargs}
{assign var="_uargs" value="do=$_action"}
{/if}
<div class="pages">
    <span>共有信息{$pageCtrl.totalrows}条 {$pageCtrl.prepage+1}/{$pageCtrl.total}
</span>

	{if $pageCtrl.haveleft }
    <a title="首页"  class="none" href="?pageno=0&{$_uargs}" rel="{$_rel}">首页</a>
    <a title="上一页"  class="none" href="?pageno={$pageCtrl.prepage}&{$_uargs}"  rel="{$_rel}">上一页</a>
    {/if}
	 {foreach key=key item=item from=$pageCtrl.lablelist}
		{if $pageCtrl.prepage+1==$item}
			<a class="current">{$item}</a>
            {else}
		<a href="?pageno={$item}&{$_uargs}" rel="{$_rel}">{$item}</a>
		{/if}
     {/foreach}

    {if $pageCtrl.haveright }
      <a title="下一页"  class="none" href="?pageno={$pageCtrl.nextpage}&{$_uargs}" 
rel="{$_rel}">下一页</a>
        <a title="末页"  class="none" href="?pageno={$pageCtrl.total}&{$_uargs}" 
rel="{$_rel}">末页</a>
	{/if}

</div>

完成后再重新看一下我们的网页,下面出现了翻页的功能,打盘DOTA庆祝下吧!

 

 

F.A.H^_^Amber

你可能感兴趣的:(职场,翻页,休闲,Pylon)