rika0225
rika0225
采纳率0%
2020-03-19 16:23

zend+smarty 搜索结果分页问题

5
已结题

zend+smarty 搜索结果分页问题


接手的别人的项目,还有很多地方搞不明白,但是时间紧急没时间给我搞明白了

现在的情况是搜索结果可以正常取值正常显示,但是点击下一页或者页码标签后搜索结果消失

如果是原生PHP或者只用框架我会做,smarty真弄不懂


求助大神了


下面是代码

  1. smarty模板层
{{**搜索↓**}}
<form action="" method="get">
    <table>
        <tbody>
        <tr>
            <td></td>
            <td>管理号 {{html_input name="id" class="form-control" value=$newsDataS.id}}</td>
            <td>
                <div>
                    作成日{{html_input name="created" class="datepicker_open form-control" size="15" value=$newsDataS.created|date_format:"%Y/%m/%d"}}
                    <span class="input-icon input-icon-nolabel icon-abui-calendar-solid" style="opacity:1;"></span>
                </div>
            </td>
            <td>标题 {{html_input name="title" class="form-control" value=$newsDataS.title}}</td>111111111111111111111111111111111111111111111111111111111111111111111111111111
            <td>管理标题{{html_input name="management_title" class="form-control" value=$newsDataS.management_title}}</td>
        </tr>
        <tr>
            <td>
                <p class="new_btn">
                    <input type="button" class="button" name="new_register" value="生成" onClick="edit('new','topic','/admin20/publicnews/input/')" />
                </p>
            </td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td>
                <div>
                    开始{{html_input name="datetime_open" class="datepicker_open form-control" size="15" value=$newsDataS.datetime_open|date_format:"%Y/%m/%d"}}
                    <span class="input-icon input-icon-nolabel icon-abui-calendar-solid" style="opacity:1;"></span>
                </div>
            </td>
            <td>
                <div>
                    结束{{html_input name="datetime_close" class="datepicker_close form-control" size="15" value=$newsDataS.datetime_close|date_format:"%Y/%m/%d"}}
                    <span class="input-icon input-icon-nolabel icon-abui-calendar-solid" style="opacity:1;"></span>
                </div>
            </td>
            <td>対象属性{{html_input name="segment_flag" class="form-control" value=$newsDataS.id_segment20}}</td>
            <td>
                <div class="col-md-12 form-group" style="text-align:left;margin-top:10px;">
                    {{html_submit id="submit" class="button" value="搜索" style="width:120px;"}}
                </div>
            </td>
        </tr>
        </tbody>
    </table>
</form>
{{**搜索↑**}}


{{if $pgS->totalItemCount > 0}}
<div class="pagination col-md-12">
    <p class="page-count">{{$pgS->firstItemNumber}} - {{if $pgS->lastItemNumber<=$pgS->totalItemCount}}{{$pgS->lastItemNumber}}{{else}}{{$pgS->totalItemCount}}{{/if}}件 / {{$pgS->totalItemCount}}件</p><!-- /.page-count -->
    <ul>
        {{**↓标记**}}
        <li class="previous {{if !$pgS->previous}}disabled{{/if}}"><a href="/admin20/publicnews/list/currentId/{{$pgS->next}}" class="icon-abui-arrow-left"></a></li>
        {{**↑标记**}}

        {{foreach from=$pgS->pagesInRange item=i name="i"}}
//这个地方我不知道怎么改,怎么让搜索到的参数传到url里
        {{if $i == $pgS->current}}
        <li class="active"><a fref="#fakelink">{{$i}}</a></li>
        {{else}}
        <li><a href="/admin20/publicnews/list/currentId/{{$i}}/id=&created=&title=&management_title=&datetime_open=&datetime_close=&segment_flag=&">{{$i}}</a></li>
        {{/if}}

        {{/foreach}}

        {if (isset($this->next))}
        <a title="Next" rel="next" class="paginator-next" href="{$this->url(['page' => $next,'search_txt'=>$prev_search_txt])}">Next</a>
        {else}
        <span class="paginator-next">Next</span>
        {/if}
        
        {{**↓标记**}}
        <li class="next {{if !$pgS->next}}disabled{{/if}}">{{if $pgS->next}}<a href="/admin20/publicnews/list/currentId/{{$pgS->next}}" class="icon-abui-arrow-right"></a>{{/if}}</li>
        {{**↑标记**}}
    </ul>
</div>
{{/if}}

{{if $pgS->totalItemCount > 0}}
<table class="table table-bordered table-hover table-striped">
    <tr>
        <th>管理号</th>
        <th>作成日</th>
        <th>标题</th>
        <th>管理标题</th>
        <th>图片</th>
        <th>开始日</th>
        <th>结束日</th>
        <th>対象属性</th>
        <th>有无发布</th>
        <th>有无优惠券</th>
        <th>有无url</th>
    </tr>
    {{foreach from=$newsDataS key="key" item="item"}}
    <tr>
        <td><p class="news_id">{{$item.id}}</p></td>
        <td style="width:20%;">
            {{$item.created|date_format:"%Y/%m/%d"}}
            <p class="ta-center">
                <input type="button" class="button" name="new" value=" 修改 " onClick="edit('edit','{{$item.id}}','/admin20/publicnews/input/');"/>&ensp;
                <input type="button" class="button" name="new" value=" 删除 " onClick="deletecheck('/admin20/publicnews/list/delete/{{$item.id}}');"/>
            </p>
        </td>
        <td><p class="news_title">{{$item.title}}</p></td>
        <td><p class="news_management_title">{{$item.management_title}}</p></td>
        <td style="width:5%;">
            {{if $item.news_image}}
            <img id="thumb_preview_session" src="/upload20/news/{{$item.news_image}}" width="160" >
            {{else}}
            无指定图片
            {{/if}}
        </td>
        <td><p class="news_datetime_open">{{$item.datetime_open}}</p></td>
        <td><p class="news_datetime_close">{{$item.datetime_close}}</p></td>
        <td><p class="news_id_segment20">{{$item.id_segment20}}</p></td>
        <td><p class="news_segment_flag">{{$item.segment_flag}}</p></td>
        <td><p class="news_management_title">{{$item.management_title}}</p></td>
        <td><p class="news_link_title">{{$item.link_title}}</p></td>

    </tr>
    {{/foreach}}
</table>
{{else}}
无情报
{{/if}}





控制层

public function listAction ()
{
    $this->_view->topicpath = array(
        '/admin20/index' => '管理画面',
        'current' => '新闻',
    );

    // session中拿数据
    $pNewsSession = new Zend_Session_NameSpace('admin20_publicnews');
    $uploadSession = new Zend_Session_NameSpace('admin20_publicnews_upload');
    $adminBrandSession = new Zend_Session_NameSpace('admin20_brand');

    // 删除优惠券session
    Zend_Session::namespaceUnset('admin20_coupon');
    Zend_Session::namespaceUnset('admin20_notification');

    // 链接DB
    $pnewsDbIns = Model_Public_News20::getInstance();

    $newsData = array();

    $memcached = new Model_Memcache20();

    // 点击删除后执行删除
    $deleteRow = $this->_getParam('delete');
    if (($deleteRow != NULL) || ($deleteRow != '')) {
        try {
            $pnewsDbIns->deleteNews($deleteRow);
        } catch (Zend_Exception $e) {
            $this->logWriter(Zend_Log::ERR, 'admin20', $e->getMessage());
            $this->logWriter(Zend_Log::ERR, 'admin20', $e->getTraceAsString());
        }
        // 从memcache中删除
        $memcached->delete($adminBrandSession->id, Model_Memcache20::MEMKEY_NEWS_LIST);

        $this->_view->delete = true;
    }

    //取得页面
    $currentId = $this->_getParam('currentId', 1);

    // ■初期表示
    try {
        // 从DB中获取数据
        $newsData = $pnewsDbIns->search(null, $currentId, self::PER_LIST, BRAND_AOKI);

        // 无限制
        $max = Azab_Db1::getNonLimitNum();

        // 生成页面
        $this->_view->pg = Zend_Paginator::factory($max)->setCurrentPageNumber($currentId)
            ->setItemCountPerPage(self::PER_LIST)
            ->getPages();

    } catch(Zend_Exception $e) {
        $this->logWriter(Zend_Log::ERR, 'admin20', $e->getMessage());
        $this->logWriter(Zend_Log::ERR, 'admin20', $e->getTraceAsString());
    }

    //递交给前台模板
    //$this->_view->assignNotSanitize('newsData', $newsData);
    $this->_view->newsData = $newsData;

    // news追加处理
    if ($this->_request->isPost() && $pNewsSession->success) {

        if ($uploadSession->filename) {
            $pNewsSession->success['news_image'] = $uploadSession->filename;
        }
        if ($uploadSession->filename_link_image) {
            $pNewsSession->success['link_image'] = $uploadSession->filename_link_image;
        }

        // 更新
        if ($pNewsSession->targetNum) {
            try {
                $pnewsDbIns->updateNews($pNewsSession->targetNum, $pNewsSession->success);
                $pNewsSession->messageFlg = 'Updated';
            } catch (Zend_Exception $e) {
                $this->logWriter(Zend_Log::ERR, 'admin20', $e->getMessage());
                $this->logWriter(Zend_Log::ERR, 'admin20', $e->getTraceAsString());
            }
        } else {
            try {
                $pnewsDbIns->commitNews($pNewsSession->success);
                $pNewsSession->messageFlg = 'Created';
            } catch (Zend_Exception $e) {
                $this->logWriter(Zend_Log::ERR, 'admin20', $e->getMessage());
                $this->logWriter(Zend_Log::ERR, 'admin20', $e->getTraceAsString());
            }
        }

        // 从memcache中删除
        $memcached->delete($adminBrandSession->id, Model_Memcache20::MEMKEY_NEWS_LIST);

        // 防止再读取
        return $this->_redirect('/admin20/publicnews/list');
    }

    /*增加搜索功能*/
    if ($this->_request->isGet()) {
        // Validate
        $filter = new Azab_Filter();
        $filter->setRules($this->getFilterRule())
            ->setValue($this->get())
            ->execute();

        $valid = new Azab_Validate();
        $valid->setValue($filter->get())
            ->setRules($this->getValidateRule())
            ->setErrorMessage($this->getErrorMessage())
            ->execute();

        $success = $valid->get('success');
        $error = $valid->get('error');

        // 输入值有问题的情况
        if (!empty($error)) {
            $success['id'] = $this->_getParam('id');
            $success['created'] = $this->_getParam('created');
            $success['datetime_open'] = $this->_getParam('datetime_open');
            $success['datetime_close'] = $this->_getParam('datetime_close');
            $success['title'] = $this->_getParam('title');
            $success['management_title'] = $this->_getParam('management_title');
            $success['id_segment20'] = $this->_getParam('id_segment20');
            $this->_view->data = $success;

            $sNewsSession = new Zend_Session_NameSpace('admin20_publicnews');

            // 发行CSRF
            $this->setSecurity($sNewsSession);

        } else {
            // 输入值正常的情况
            // 显示搜索结果
            $success['id'] = $id = $this->_request->getParam('id', null);
            $success['created'] = $created = $this->_request->getParam('created', null);
            $success['datetime_open'] = $datetime_open = $this->_request->getParam('datetime_open', null);
            $success['datetime_close'] = $datetime_close = $this->_request->getParam('datetime_close', null);
            $success['title'] = $title = $this->_request->getParam('title', null);
            $success['management_title'] = $management_title = $this->_request->getParam('management_title', null);
            $success['id_segment20'] = $id_segment20 = $this->_request->getParam('id_segment20', null);
            $this->_view->data   = $success;

            $newsDataS = array();

            // 取得页码(默认第一页)
            $currentId = $this->_getParam('currentId', 1);

            try {
                // 从DB中取数据
                $newsDataS = $pnewsDbIns->searchNews(null, $currentId, self::PER_LIST, BRAND_AOKI, $id, $created, $datetime_open, $datetime_close, $title, $management_title, $id_segment20);
                // 无限制
                $max = Azab_Db1::getNonLimitNum();

                // 生成页面
                $this->_view->pgS = Zend_Paginator::factory($max)->setCurrentPageNumber($currentId)
                    ->setItemCountPerPage(self::PER_LIST)
                    ->getPages();

            } catch (Zend_Exception $e) {
                $this->logWriter(Zend_Log::ERR, 'admin20', $e->getMessage());
                $this->logWriter(Zend_Log::ERR, 'admin20', $e->getTraceAsString());
            }

            // 递交给前台
            //$this->_view->assign('newsDataS', $newsDataS);
            $this->_view->newsDataS = $newsDataS;
            $this->logWriter(Zend_Log::INFO, '', print_r ($newsDataS, true));
            // 
            $sNewsSession->success = $success;

        }

    }

    foreach ($newsDataS as &$row) {
        $row = str_replace('\"', '"', $row);
    }

    $this->_view->messageFlg = $pNewsSession->messageFlg;

    Zend_Session::nameSpaceUnset('admin20_publicnews');
    Zend_Session::nameSpaceUnset('admin20_publicnews_upload');
}




















  • 点赞
  • 收藏
  • 复制链接分享

2条回答

  • yan88888888888888888 大广-全栈开发 1年前

    返回 json 多好 为啥要用session 会有限制

    点赞 评论 复制链接分享
  • rika0225 rika0225 1年前

    接手的项目,搜索部分是自己写的,一开始是post,想用session来保存结果再传给前台但是怎么也取不到,只好改用get,求大神帮帮忙

    点赞 评论 复制链接分享