Fluid interface

Permalink
It appears that none of these PageList filter or sort methods have a return value. It would be very convenient if they returned $this so that you could chain methods together. For example:

$pageList = new PageList();
$pages = $pageList->filterByIsApproved($cvIsApproved)
         ->filterByUserID($uID)
         ->sortByPublicDate()
         ->get();

 
ijessup replied on at Permalink Reply
ijessup
I believe you can just do this:
$pageList = new PageList();
$pageList->filterByIsApproved($cvIsApproved);
$pageList->filterByUserID($uID);
$pageList->sortByPublicDate();
$pages = $pageList->get();
From a coding elegance point of view, I agree with you. However, it's not entirely necessary.
sparkymeister replied on at Permalink Reply
Yes, you can do it that way. Actually, you have to. I'm just saying that a fluent interface would be nice and it would not break backwards compatibility.
ijessup replied on at Permalink Reply
ijessup
Again, I certainly agree.

You could always mod the core and submit a diff file to the c5 guys. I know Andrew has uploaded a number of mod's I've made to c5's Github account.
jkoudys replied on at Permalink Reply
Did anyone ever follow up on this? I come from the Rails world and returning a $this would definitely make it a lot quicker to write and easier to read. I find myself repeatedly instantiating PageLists, running all these filters having to write my pagelist variable name over and over again, only to pass it in to a foreach() and never use it again. I really don't need that reference to my pagelist staying in scope at any point after that. The whole thing would be nicer if I could just write it all inside my foreach() statement.

This website stores cookies on your computer. These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media. To find out more about the cookies we use, see our Privacy Policy.