Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Paginator default rendering #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SmiSoft
Copy link

@SmiSoft SmiSoft commented Apr 15, 2018

To prevent code duplication in templates in one application and across applications, default rendering implemented.

To prevent code duplication in templates in one application and across applications, default rendering implemented.
@dracony
Copy link
Member

dracony commented Apr 15, 2018

Thanks for your effort!
Any html should really not be in this package though. This package is totally agnostic from the presentation layer.

The best apptoach would be to create a bundle with the pagination template. Having it in a bundle means you can include it in any other template on your website.

E.g. an example of a bundle: https://github.com/PHPixie/Framework-Bundle

This bundle includes the default templates for exception pagrs and such. So you can add a pager template to this one.

@SmiSoft
Copy link
Author

SmiSoft commented Apr 15, 2018

Hmmm... there are some frameworks, in which paginators contains render function, which generates ready HTML code:

  • Kohana (I make some projects with it, it was the mostly comfortable for me, but dead now), for the sake of justice, it's component contains separated views (templates in your terms), but combined in one module
  • CodeIgniter (my second favourite fw, but I can't determine is it alive, or not), but it's render() function cannot be customized (HTML code build in, pity)
  • FuelPHP
  • CakePHP
    they all contains render() function inside pagination object (templates may be separated). So, I think that placing render() function in paginate object is a good choice (even if it contain HTML code).
    Also, take a look: all options like HTML custom code, URL and so on are translated from template (View part of MVC), so this location of code don't break MVC conception.
    The slightly better choice is to move HTML code to template (located inside paginator module, certainly, not in other module/bundle, this is very strange to separate connected operations between two modules!), which can be rendered:
// somewhere in template file: /bundles/app/assets/templates/news.php
<?=$data->render('simple'); ?>

and template should be located somewhere in /vendor/phpixie/paginate/assets/template/simple.php. This should be a "pure" PHP code (to prevent link to a template module). But I don't see a solution for at least two issues:

  • what to do, if a user create new pagination's template /bundles/app/assets/templates/complex.php and wish to use it?
  • how easily extend plain PHP code? For example, user wans to replace '<<<' and '>>>' to russian 'В начало' (to the first page) and 'В конец' (to the last page) and place the result to /bundles/app/assets/template/russian.php? Copy/paste code? Not a choice! In my variant, this may be done with two lines of code (transfer two modified option to the paginator).

@dracony
Copy link
Member

dracony commented Apr 15, 2018

Clear responsibility separation is one of the main feature of PHPixie architecture. The Paginate package is the data layer for pagination and should not contain anything extra, especially not HTML templates. It is in fact very common to separate related but distinct operations between modules, for example database layer and ORM layer. The entire idea of MVC stemmed from applying such separation. Furthemore having the Paginate library actually read templates from some folder would even further breach the single-responsibility principle

Also there is no point to invent a new templating method if we have a great PHPixie/Template library to use for templating.

In any case, who really needs a premade paginator templating code? Everybody will end up having some custom UI for pagination relative to the rest of their website anyway. It only makes sense in contexts like "a premade PHPixie template for Bootstrap 4 pagination" which sounds like a good idea for Bootstap4 bundle for PHPixie.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants