• Phalcon之分页


    Phalcon分页,虽然官网有例子,但关于builder的写法,还是让我头疼了很久,

    controller部分

    $builder = $this->modelsManager->createBuilder()
    ->columns('books.id,books.book_name,books.author,books.press,books.status,books.own_id,u.email')
    ->from('books')
    ->leftjoin('users', 'books.own_id = u.id','u')    //一旦用了alias ,则都需要用别名 ,leftjoin是自己瞎蒙的,API里没看到这个函数
    ->orderBy('books.status');

    $paginator = new PhalconPaginatorAdapterQueryBuilder(array(
    "builder" => $builder,
    "limit"=> 2,
    "page" => $currentPage,
    ));

    $page = $paginator->getPaginate();

    //获取里面的值,测试用,看是否拿到join的数据

    foreach($page->items as $items){ //皆可得到
    echo $items->author;
    echo $items->email;
    exit;
    }

    view下面--推荐用bootstrap

    <?php if($page->total_pages > 1):?>
    <div class="page_margin">
    <ul class="pagination ">
    <li class="<?php echo $page->current <= 1?'disabled':''; ?>"><a href="<?php echo $this->url->get('index/index',array('page'=>$page->before));?>">&laquo;</a></li>
    <?php for($i = 1;$i <= $page->total_pages;$i++):?>
    <li class="<?php echo $page->current == $i?'active':''; ?>"><a href="<?php echo $this->url->get('index/index',array('page'=>$i));?>"><?php echo $i; ?></a></li>
    <?php endfor; ?>
    <li class="<?php echo $page->current >= $page->total_pages?'disabled':''; ?>"><a href="<?php echo $this->url->get('index/index',array('page'=>$page->next));?>">&raquo;</a></li>
    </ul>
    </div>
    <?php endif;?>

    相关链接:

    http://www.myleftstudio.com/reference/pagination.html  //Phalcon官网讲解

    1、以专家为榜样,不必自己重新探索
    2、解构技能,找出实现80%效果的那20%
    3、不要一心二用
    4、练习练习再练习!然后获得即时反馈
    5、坚持,不要在低谷期放弃
  • 相关阅读:
    LPC 网络编程
    LPC 语言基础
    (lua) 基于cocos 的插入光效
    lua_table 学习
    lua 语言基础
    C++ 三大特性:封装、继承、多态性
    C++的编译预处理
    C++ 用变量定义数组
    C++ STL常用容器浅析
    拦截器的文章 写的可以!
  • 原文地址:https://www.cnblogs.com/zhongyuan/p/3782655.html
Copyright © 2020-2023  润新知