Answer the question
In order to leave comments, you need to log in
What to do with repetitive methods?
Hello! The site has about a dozen separate modules: "news", "events", "comments", etc. And each module, respectively, has its own class in which it is generated.
Each of them has a pagination that is generated by a single external paginator() function;
But for each, you need to pass parameters when connecting: "current page", "amount per page", etc.
It turns out that each class has the same methods: setPage() , setOnPage() , getStart() , getLimit()and so on ... In addition to these, there are still the same ones. How to deal with it? on the one hand, you can throw them into a separate class, and on the other hand, it will turn out that the classes depend on each other, because these methods will have to change the properties of the same name in each of the classes.
Answer the question
In order to leave comments, you need to log in
You are probably designing your application incorrectly. Pagination is usually placed in a separate module/class. I recommend to look at popular PHP OOP frameworks.
I also recommend reading: about inheritance in PHP
You can do this:
Create an interface
public interface PagedListInterface
{
//..
PageIndex
PageSize
TotalCount
TotalPages
//..
}
class PagedList implements PagedListInterface
{
//тут вся логика листалки
}
public interface NewsInterface
{
//Различные методы
//И среди прочих
PagedListInterface GetNewsList()
}
class News implements NewsInterface
{
public PagedListInterface GetNewsList()
}
You need to use inheritance.
Or a separate class must be written for pagination.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question