RE: RE: AW: [SMARTY] Paging
| From: | Monte Ohrt | Date: | Thu, 12 Dec 2002 14:44:37 +0000 |
| Subject: | RE: RE: AW: [SMARTY] Paging | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-6771@lists.php.net to get a copy of this message | ||
I Keep the pagination in the application logic, and assign the result
set to the template. There are some obvious efficiency reasons for doing
things this way. Don't mess with math in the templates if you don't have
to, it is also not efficient. As far as designer control, put the
pagination variables in a config file. That way the application can read
them, and the designer can change them. You can use config files from
your app like so:
$conf = new Config_File('./configs');
$limit = $conf->get('my.conf', null, 'records_per_page');
Another possible solution (that I haven't tried) is running the query
after the template has started execution by way of a include_php.
{include_php file="load_page_records.php" start=$start limit=$limit}
There's even a start of this method in an example:
http://smarty.php.net/manual/en/language.function.include.php.html
The script still needs to know what query to run and that is not
something you want to pass from the template, so some more application
design needs to be thought out here. As long as the application knows
what query to execute ahead of time, the pagination data could come from
the template in this manner. But using config files is easier and
cleaner anyway so I use them.
Monte
On Thu, 2002-12-12 at 06:43, Ben Phillips wrote:
> > I made a similar plugin a while back ... it's highly
> > impractical, because you're putting SQL statements in Smarty
> > templates - the layout templates get "polluted" with
> > functionality, which means you expose this functionality to
> > the designer. Also, by performing the SQL query inside the
> > template, you make it impractical to perform any additional
> > post-query PHP-processing on the query-result.
>
> the query isn't exposed in the template. it can be, or it can be set in
> the php code so that the template designer simply calls the plugin with
> the query variable. the query is often never seen by the designer.
>
> > Functionality like paging doesn't really belong in a Smarty
> > plugin, for a template designer to use - because most
> > template designers don't know how to; it belongs in a PHP
> > library, where the programmer can use it.
>
> i have to disagree with this. the designer may or may not wish to use
> paging, depending on the type of page they are designing. they will also
> wish to position the results from the query as well as the navigation
> string wherever they like. they may also want to alter the text for the
> navigation string, and how it is displayed - options that should be made
> available for them when they are designing the template. these options
> are set by the designer, not the php programmer and therefore the
> designer should have access to the functionality.
>
> what if they want to display 10 results per page? or 20? that's not up
> to the php programmer - that's in the realm of the designer.
>
> if there is a more elegant way of doing this, then please let me know.
>
> benji.
--
Monte Ohrt <monte@ispi.net>