0

I'm writing a custom plugin to tap into an external database, and I'm getting the overall results I want. However, I want to wrap my return values around a conditional to avoid processing unnecessary queries further down the line - this bit doesn't seem to be working :-/

Basically I want to check whether the current date is Christmas Day. So I have this early on in my logic:

    if($date[2]=="25" && $date[1]=="12") {
        $this->return_data = '<p>Sorry, there are no sailings on Christmas Day.</p>';
    }

If it is 25/12, then obviously output the above message and ignore the rest of the plugin, otherwise run the SQL and return a timetable.

Whats happening is (when I change the date to today) it continues through the plugin, always outputting the timetable, presumably because I've nothing to stop the plugin after it returns the data in this conditional.

Do I need to wrap this in an if/else structure? Or can I break the processing somehow?

4

After setting the return data, you need to return program control to the Template class, which ends execution of the current method.

if ($date[2] == 25 && $date[1] == 12)
{
      $this->return_data = '<p>Sorry, there are no sailings on Christmas Day.</p>';
      return;
}

Incidentally, it isn't necessary to set the $return_data class property unless your plugin only operates in its constructor. So most plugin/module methods can simply return their output:

if ($date[2] == 25 && $date[1] == 12)
{
      return '<p>Sorry, there are no sailings on Christmas Day.</p>';
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.