Jump to content

Aha! Moments


DaveP
 Share

Recommended Posts

"A moment of sudden realization, inspiration, insight, recognition, or comprehension." (Merriam-Webster)

(Nothing to do with these guys.)

You are cordially invited to share your PW Aha! moments here. Hopefully others will benefit.

For instance, the project I am currently working on includes a form to allow the entry of televised football fixtures (Time/Date, Home team, Away team). This is implemented as a PageTable and I needed to list any lines already existing and a blank line to allow the entry of a new fixture. foreach-ing through the existing fixtures is easy, but how to cleanly (in programming terms) add a blank line?

$a->makeBlankItem()!

$fixtures = $pages->find("template=fixture");
$emptyFixture = $fixtures->makeBlankItem();
$fixtures->append($emptyFixture);

foreach($fixtures as $fixture){
    ...do stuff..
}
And that will include a blank fixture at the end. The ...do stuff... will very likely be form inputs.

(I know a couple of lines could be chained (okay, 1-3), but it reads easier to me as it is.)

  • Like 8
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...