Skip to content

Instantly share code, notes, and snippets.

@objectivehtml
Last active January 3, 2016 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save objectivehtml/8505185 to your computer and use it in GitHub Desktop.
Save objectivehtml/8505185 to your computer and use it in GitHub Desktop.
<?php
// This is a module method. Use it like so...
// {exp:module_name:class_achievements course_url_title="{segment_3}"}
public function class_achievements()
{
// Course is a model I created. findUrlTitle() is an inherited static method
if(!$course = Course::findByUrlTitle($this->param('course_url_title')))
{
// If no course is found, return the noResults() method.
return ChannelEntriesParser::noResults();
}
// Achievements is another model that is related to courses. Course
// has a method name achievements to fetch these related models.
if(!$achievements = $course->achievements())
{
// And if no achievements, return noResults() method.
return ChannelEntriesParser::noResults();
}
// If all is successfully, return the related achievements as a Channel Entries loop
return $achievements->entries();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment