You were right. I misplaced the function under the final '}' of the function HomePage_Controller extends Page_Controller.
The Home page is of HomePage type. Now the code looks like this:
HomePage.php
<?php
class HomePage extends Page {
public static $db = array(
);
public static $has_one = array(
);
}
class HomePage_Controller extends Page_Controller {
public function init() {
parent::init();
// Note: you should use SS template require tags inside your templates
// instead of putting Requirements calls here. However these are
// included so that our older themes still work
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
/**
* Site search form
*/
function SearchForm() {
$searchText = isset($_REQUEST['Search']) ? $_REQUEST['Search'] : 'Search';
$fields = new FieldSet(
new TextField("Search", "", $searchText)
);
$actions = new FieldSet(
new FormAction('results', 'Search')
);
return new SearchForm($this, "SearchForm", $fields, $actions);
}
/**
* Process and render search results
*/
function results($data, $form){
$data = array(
'Results' => $form->getResults(),
'Query' => $form->getSearchQuery(),
'Title' => 'Search Results'
);
return $this->customise($data)->renderWith(array('Page_results', 'Page'));
}
function LatestNewsItems($num=5) {
$newssection = DataObject::get_one("News");
Debug::show($newssection);
return ($newssection) ? DataObject::get("Article01", "ParentID = '$news->ID'", "Date DESC", "", $num) : false;
}
}
?>
I get an error though:
[User Error] Bad class to singleton() - News
GET /silverstripe/?flush=1
Line 261 in C:\wamp\www\silverstripe\sapphire\core\Core.php
Source
252 *
253 * @param string $className
254 * @return Object
255 */
256 function singleton($className) {
257 global $_SINGLETONS;
258 if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
259 if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
260 if(!isset($_SINGLETONS[$className])) {
261 if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
262 $_SINGLETONS[$className] = Object::strong_create($className,null, true);
263 if(!$_SINGLETONS[$className]) user_error("singleton() Unknown class '$className'", E_USER_ERROR);
264 }
265 return $_SINGLETONS[$className];
266 }
267
Trace
* Bad class to singleton() - News
Line 261 of Core.php
* singleton(News)
Line 2464 of DataObject.php
* DataObject::get_one(News)
Line 56 of HomePage.php
* HomePage_Controller->LatestNewsItems()
* call_user_func_array(Array,Array)
Line 318 of ViewableData.php
* ViewableData->obj(LatestNewsItems)
Line 50 of .cacheC..wamp.www.silverstripe.themes.riffinsolvency.templates.Layout.HomePage.ss
* include(C:\Windows\Temp\silverstripe-cacheC--wamp-www-silverstripe\.cacheC..wamp.www.silverstripe.themes.riffinsolvency.templates.Layout.HomePage.ss)
Line 354 of SSViewer.php
* SSViewer->process(HomePage_Controller)
Line 346 of SSViewer.php
* SSViewer->process(HomePage_Controller)
Line 175 of Controller.php
* Controller->handleAction(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 29 of ModelAsController.php
* ModelAsController->handleRequest(HTTPRequest)
Line 44 of RootURLController.php
* RootURLController->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/)
Line 118 of main.php
Can you please help me out?
Nice day, to everybody!