Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

[[edited]] including code within a function


Go to End


1144 Views

Avatar
bmc38119

Community Member, 45 Posts

7 March 2008 at 5:47am

Edited: 07/03/2008 8:43am

using the tutorial code as an example, is it possible to call a function from an include file on

/**
 * Defines the HomePage page type
 */
 
class HomePage extends Page {
   static $db = array(
   );
   static $has_one = array(
   );
 
}
 
class HomePage_Controller extends Page_Controller {

function LatestNews() {
include('FunctionLatestNews.php')
}	

}
?>

where FunctionLatestNews.php contains the following code:

  $news = DataObject::get_one("ArticleHolder");
  return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", 5) : false;

just thinking where this code could be reused on other page controllers.