Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Paginator Iterator 0.1 Released

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons
View previous topic :: View next topic  
Author Message
ameggiolaro
Smarty n00b


Joined: 07 Aug 2008
Posts: 4

PostPosted: Thu Aug 07, 2008 6:58 pm    Post subject: Paginator Iterator 0.1 Released Reply with quote

Hello everybody, I'm new at this forum and I've wrote a add-on/plugin to Smarty called PaginatorIterator.

Features:
- Paginates results from a given SQL
- Iterates the paginated results (p_item and p_alternating plugins)
- Allows to create a page navigator
- Shows a header content (p_header plugin) and footer content (p_footer plugin)
- Shows a empty template when there is no results (p_empty plugin)
- Allows to create plugins to handle the database queries
- Don't uses sessions to store any data
- You can to use it in a MVC application
- You can create your own pagination style
- For while it supports mysql_*, mysqli_*, pdo (mysql and pgsql), but you can create your own plugins for others databases

Download it here :
http://www2.unijui.edu.br/~anderson.m/pi/

If you test it, please send me some feedback, like bugs reporting, etc.

Sample code:

Code:

// example.php

include('pi_lib/PaginatorIterator.php');

$mysql=@mysql_connect('localhost', 'root', '123456', 'j15') or die('Cant connect');
mysql_select_db('j15', $mysql);

PaginatorIterator::setHandlerFunc('mysql'); # defaults to pdo
PaginatorIterator::setConnection($mysql);

include('Smarty-2.6.19/Smarty.class.php');
$smarty=new Smarty;
$smarty->plugins_dir[]="./plugins";

$smarty->assign('ds', "select name, link from jos_menu limit :LIMIT offset :OFFSET");
$smarty->assign('numrows', "select count(*) from jos_menu");

$smarty->display("example.tpl");



Code:

<!-- example.tpl -->

{p_iterator id="rec" ds=$ds numrows=$numrows rowsperpage=6 pageno=$smarty.get.pageno}

   {p_header}
      <div class="paginator" align="center">
         {if $rec.is_first_page}
            <a class="first-last">First</a>
            <a class="first-last">Prev</a>
         {else}
            <a href="example.php?pageno={$rec.first}">First</a>
            <a href="example.php?pageno={$rec.prev}">Prev</a>
         {/if}
         
         {section name="i" loop=$rec.pages}
            {if $rec.pages[i] ne $rec.pageno}
               <a href="example.php?pageno={$rec.pages[i]}">{$rec.pages[i]}</a>
            {else}
               <span>{$rec.pages[i]}</span>
            {/if}
         {/section}

         {if $rec.is_last_page}
            <a class="first-last">Next</a>
            <a class="first-last">Last</a>
         {else}
            <a href="example.php?pageno={$rec.next}">Next</a>
            <a href="example.php?pageno={$rec.last}">Last</a>
         {/if}
      </div>

      <br/><br/>
      <table width="100%" border="1">
   {/p_header}
   
   {p_item}
      <tr>
         <td>{$rec.data.name}</td>
         <td>{$rec.data.link}</td>
      </tr>
   {/p_item}

   {p_alternating}
      <tr style="background-color:#FFFF99;">
         <td>{$rec.data.name}</td>
         <td>{$rec.data.link}</td>
      </tr>
   {/p_alternating}

   {p_empty}
      <tr>
         <td>No records found</td>
      </tr>
   {/p_empty}

   {p_footer}
      </table>
   {/p_footer}

{/p_iterator}


Thanks,

Anderson A. Meggiolaro
IT Programmer


Last edited by ameggiolaro on Thu Aug 07, 2008 7:55 pm; edited 1 time in total
Back to top
View user's profile Send private message
darlinton
Smarty n00b


Joined: 07 Aug 2008
Posts: 1

PostPosted: Thu Aug 07, 2008 7:07 pm    Post subject: Re: Paginator Iterator 0.1 Released Reply with quote

Nice, good work!

Darlinton Prauchner
Programador/Webdesigner
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Aug 07, 2008 7:27 pm    Post subject: Reply with quote

Good stuff, although I'd recommend against passing SQL queries through the template. Depending on how well you trust your template designers, someone could do:

{p_iterator ... ds="truncate table jos_menu"}

and cause some problems. Maybe a query placeholder instead?

{p_iterator ... ds="sel_jos_menu"}

and sel_jos_menu is defined as the appropriate query in PHP.
Back to top
View user's profile Send private message Visit poster's website
ameggiolaro
Smarty n00b


Joined: 07 Aug 2008
Posts: 4

PostPosted: Thu Aug 07, 2008 7:36 pm    Post subject: Reply with quote

mohrt wrote:
Good stuff, although I'd recommend against passing SQL queries through the template. Depending on how well you trust your template designers, someone could do:

{p_iterator ... ds="truncate table jos_menu"}

and cause some problems. Maybe a query placeholder instead?

{p_iterator ... ds="sel_jos_menu"}

and sel_jos_menu is defined as the appropriate query in PHP.


Thanks for your feedback, I didn't have thought about that. I'll work in a 0.2 version as sooner as possible.

Anderson
Back to top
View user's profile Send private message
ameggiolaro
Smarty n00b


Joined: 07 Aug 2008
Posts: 4

PostPosted: Thu Aug 07, 2008 7:48 pm    Post subject: Reply with quote

mohrt wrote:
Good stuff, although I'd recommend against passing SQL queries through the template. Depending on how well you trust your template designers, someone could do:

{p_iterator ... ds="truncate table jos_menu"}

and cause some problems. Maybe a query placeholder instead?

{p_iterator ... ds="sel_jos_menu"}

and sel_jos_menu is defined as the appropriate query in PHP.


Hello again, if you saw the examples, you'll see that in applications MVC-like that problem don't happens.
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Aug 07, 2008 8:21 pm    Post subject: Reply with quote

The examples are the same? AFAIK in an MVC architecture, SQL happens in the model, and not passed through the view.
Back to top
View user's profile Send private message Visit poster's website
ameggiolaro
Smarty n00b


Joined: 07 Aug 2008
Posts: 4

PostPosted: Fri Aug 08, 2008 12:26 am    Post subject: Reply with quote

mohrt wrote:
The examples are the same? AFAIK in an MVC architecture, SQL happens in the model, and not passed through the view.


Please see "example2.php" and "models/MenuModel.php"

Anderson
Back to top
View user's profile Send private message
bfrcanthis
Smarty n00b


Joined: 08 Feb 2012
Posts: 1

PostPosted: Wed Feb 08, 2012 10:39 am    Post subject: Reply with quote

Hello Everyone!
I've upgraded to Smarty 3.1.7, and got this error - "SmartyException: template property '_paginator' does not exist. in 'smarty_internal_template.php' on line 668"

Maybe someone had similar problem and have any suggestions how to fix it?

ATTENTION! Problem fixed!
Read this, helped me a lot..
http://www.phpclasses.org/discuss/package/4743/thread/2/
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Add-ons All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP