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.

Template Questions /

Change the page type of the homepage in the CMS


Go to End
Reply


13 Posts   5783 Views

Avatar
ioWow

Community Member, 6 Posts

17 June 2009 at 8:44pm

Hi

We (ioWow) are newbies to Silverstripe but not to web development. Having said that, we are (not just I) having problems trying to create a second template to use as the default landing page, but have already got the main site template set and running nicely.

I have spent hours scouring the forum for tips, and in particular spent a couple of hours going through the steps recommended in the Tutorial 1: Building a Basic Web Site > mostly because it took me a couple of hours to figure out just what you meant by flushing in reference to the database....how? nothing was clearly said except for the flush command (append /?flush=1) ....in the end I worked out that what was meant was: type the flush command in the URL bar of your browser as a normal URL but with the flush command appended to the domain name..... Ok it worked...I even found I could FLush=all...sorry but not quite a YAY! yet.

(Suggestion: the writer(s) of the guide and a lot of the people who help with advice, assume everyone has a level of expertise that you have gained with familiarity and no doubt months and months if not years of experience....to those of use who don't have that familiarity and who have always assumed a flush command refers to the rest room....why not just add the text: "Add / Append /?flush=1 to your domain name in the URL bar of your browser"... and that ends all those hours spent trying to work out how to....simple, use your browser not mYSQL, PHPMyadmin etc etc)

But that's not what I am posting for this time.

I have completed the following steps setting up this new home page:

1. Create a new page type
In notepad, added the code below to a new blank page and created
a new file HomePage.php

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
);
static $has_one = array(
);

}

class HomePage_Controller extends Page_Controller {
   
}
?>

Step 2. Upload to mysite/code directory in our test site.

Step 3. Update the database using /?flush=1 command
For example - http://www.ourdomain.com/?flush=1
(have also used /?flush=all

Step 4. Go to the CMS and ...???

Well the tutorial says: As we have just created a new page type, SilverStripe will add this to the list of page types in the database

<Heading>Changing the page type of the Home page

After building the database, we can change the page type of the homepage in the CMS, under the “Behaviour” tab. Change it to HomePage, and click “Save Draft” and “Publish”.

...AND here we start having problems again. I / we look in the CMS and create a new page but cannot find any option to Change to a Home Page.

Currently a Page is there...as is Change to Error Page, Redirector Page, Subscribe Form, User Defined and Virtual. BUT Change to a Home Page is not in this drop down menu.

Once I can define the new home page as a home page and assign a new template (next step after we resolve this step) we will be cruising...

Your advice, help and comments are more than appreciated.

Daniel
ioWow

Avatar
banal

Community Member, 901 Posts

17 June 2009 at 9:15pm

Edited: 17/06/2009 9:17pm

Hi and welcome to SilverStripe.
I hope you enjoy your stay :)

You're mixing up things. The "flush" command is there to clean the cached files created by the template engine. You usually need this if you're changing template files. It has nothing to do with building the Database.

Whenever you add new page types, modules or you add DB relations/fields to your existing pages, you have to re-build your DB. To do that, append /dev/build to your site url.
It is actually correctly described in Tutorial 1, Section Creating a new page type. As you can see there, the URL to call is:
http://localhost/dev/build?flush=1

The tutorial assumes, you're running your site on http://localhost. You may exchange this with http://yoursite.com .. or whatever.
The flush part isn't mandatory AFAIK (at least no longer in SilverStripe 2.3). The /dev/build is important, as it actually triggers a DB-rebuild.

After that, you should be able to access your newly created page-type (to be on the safe side, enter the cms by appending /?flush=1, eg. http://localhost/admin/?flush=1).
HTH

Avatar
ioWow

Community Member, 6 Posts

18 June 2009 at 5:47pm

Hi HTH

Thanks for your reply. I do appreciate it..and yes, I was mixing up what Flush does.

I tried again to use the /dev/build?flush?=1 command and the only response I get is:

Page not found

Sorry, it seems you were trying to access a page that doesn't exist.

Please check the spelling of the URL you were trying to access and try again.

....I also tried variations. Maybe you wouldn't mind and see for yourself. Our test site
is here:
http://test.iowow.com/bananaparadise/

The url I tried to use was: http://test.iowow.com/bananaparadise/dev/build?flush=1

Thanks for your help again

Daniel

Avatar
banal

Community Member, 901 Posts

18 June 2009 at 6:34pm

Edited: 18/06/2009 6:34pm

Hi Daniel

It seems like you're running a rather old version of SilverStipe (2.0?). The best thing would probably be updating. If that's not an option, use /db/build?flush=1, that's what the URL was before 2.3. Remember: You have to be logged in to the CMS to do that.

Oh and by the way: HTH means "Hope That Helps" :)
Best - Roman

Avatar
ioWow

Community Member, 6 Posts

19 June 2009 at 10:27pm

Hi Roman

Thanks for your reply. I do appreciate it.

I tried that and fried the site...so I searched for the latest version, cleaned the site, re-installed the datatabase, loaded the new version SilverStripe-v2.3.2 and started the install...and then ran into this error message:

[User Error] Uncaught ReflectionException: Class HomePage does not exist
POST /install.php

Line 216 in ....../sapphire/core/Object.php

207             $replacedInbuilt = array_key_exists($name, $replacedProps) ? $replacedProps[$name] : null;
208             
209             if($ancestorInbuilt != $replacedInbuilt) {
210                $value = is_array($ancestorInbuilt) ? array_merge($ancestorInbuilt, (array) $extra) : $extra;
211             } else {
212                $value = $extra;
213             }
214          } else {
215             // get a built-in value
216             $reflector = new ReflectionClass($class);
217             $props = $reflector->getStaticProperties();
218             $inbuilt = array_key_exists($name, $props) ? $props[$name] : null;
219             $value = isset($extra) && is_array($extra) ? array_merge($extra, (array) $inbuilt) : $inbuilt;
220          }
221          
222          self::$cached_statics[$class][$name] = true;

Trace

* ReflectionClass->__construct(HomePage)
Line 216 of Object.php
* Object::get_static(HomePage,db)
Line 254 of Object.php
* Object::uninherited_static(HomePage,db)
Line 2013 of DataObject.php
* DataObject::has_own_table(HomePage)
Line 89 of ClassInfo.php
* ClassInfo::dataClassesFor(SiteTree)
Line 2251 of DataObject.php
* DataObject->buildSQL(URLSegment = 'home')
Line 2516 of DataObject.php
* DataObject->instance_get_one(URLSegment = 'home',)
Line 2461 of DataObject.php
* DataObject::get_one(SiteTree,URLSegment = 'home')
Line 927 of SiteTree.php
* SiteTree->requireDefaultRecords()
Line 214 of DatabaseAdmin.php
* DatabaseAdmin->doBuild(1)
Line 797 of install.php
* Installer->install(Array)
Line 123 of install.php

Not sure what to do now..our programmers have not seen this error before. Should I go back to the older version which installed fine, or does someone have a solution? (I know this error should actually go into the Installing part of the forum..but would loose the thread of whats happened so far).

Hope someone can help. I really do want to install the unique home page using the CMS instead of creating an external landing page.

Crossing fingers and toes

Daniel

Avatar
banal

Community Member, 901 Posts

20 June 2009 at 12:30am

Apparently, SilverStripe cannot find the HomePage class. Did you do a clean install and moved your page classes to the mysite/code folder afterwards? If the HomePage class is in mysite/code and your mysite/_config.php contains the following lines:

global $project;
$project = 'mysite';

Then a dev/build should solve the issue...

Avatar
ioWow

Community Member, 6 Posts

20 June 2009 at 7:58pm

Hi Banal

I had to do two clean installs (delete everything and start a second time) and everything eventually worked OK.
I entered the CMS and could see the start pages with the default Silverstripe theme.

I then uploaded our modified theme (changes to the "blackcandy"them) and saw the theme applied OK. I then uploaded the new Home Page Class (homepage.php) to /mysite/code and then ran /?flush=1 and this stopped at the same place as last time (Class Home Page does not exist).

I checked that ....

global $project;
$project = 'mysite';

...was included in _config.php, and then ran /dev/build as advised...and got this error message:

Environment Builder (formerly db/build)
http://www.2thaiparadise.eu/
dev→ build
Building Database stebraco_2thaiparadis

Creating database tables
# PageComment
# SiteTree
# Field SiteTree.ClassName: changed to enum('SiteTree','Page','GhostPage','HomePage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree' (from enum('SiteTree','Page','GhostPage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree')
# Field SiteTree_Live.ClassName: changed to enum('SiteTree','Page','GhostPage','HomePage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree' (from enum('SiteTree','Page','GhostPage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree')
# Field SiteTree_versions.ClassName: changed to enum('SiteTree','Page','GhostPage','HomePage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree' (from enum('SiteTree','Page','GhostPage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree')
# Email_BounceRecord
# QueuedEmail
# File
# Group
# LoginAttempt
# Member
# MemberPassword
# Permission
# Widget
# WidgetArea
# Page
# GhostPage
# ErrorPage
# RedirectorPage
# VirtualPage
# Image
# Folder
# Image_Cached

Creating database records
# PageComment
# SiteTree
[User Error] Uncaught ReflectionException: Class HomePage does not exist
GET /dev/build

Line 216 in ....../sapphire/core/Object.php
Source

207             $replacedInbuilt = array_key_exists($name, $replacedProps) ? $replacedProps[$name] : null;
208             
209             if($ancestorInbuilt != $replacedInbuilt) {
210                $value = is_array($ancestorInbuilt) ? array_merge($ancestorInbuilt, (array) $extra) : $extra;
211             } else {
212                $value = $extra;
213             }
214          } else {
215             // get a built-in value
216             $reflector = new ReflectionClass($class);
217             $props = $reflector->getStaticProperties();
218             $inbuilt = array_key_exists($name, $props) ? $props[$name] : null;
219             $value = isset($extra) && is_array($extra) ? array_merge($extra, (array) $inbuilt) : $inbuilt;
220          }
221          
222          self::$cached_statics[$class][$name] = true;

Trace

* ReflectionClass->__construct(HomePage)
Line 216 of Object.php
* Object::get_static(HomePage,db)
Line 254 of Object.php
* Object::uninherited_static(HomePage,db)
Line 2013 of DataObject.php
* DataObject::has_own_table(HomePage)
Line 89 of ClassInfo.php
* ClassInfo::dataClassesFor(SiteTree)
Line 2251 of DataObject.php
* DataObject->buildSQL(URLSegment = 'home')
Line 2516 of DataObject.php
* DataObject->instance_get_one(URLSegment = 'home',)
Line 2461 of DataObject.php
* DataObject::get_one(SiteTree,URLSegment = 'home')
Line 927 of SiteTree.php
* SiteTree->requireDefaultRecords()
Line 214 of DatabaseAdmin.php
* DatabaseAdmin->doBuild(,1)
Line 100 of DatabaseAdmin.php
* DatabaseAdmin->build()
Line 135 of DevelopmentAdmin.php
* DevelopmentAdmin->build(HTTPRequest)
Line 129 of RequestHandler.php
* RequestHandler->handleRequest(HTTPRequest)
Line 122 of Controller.php
* Controller->handleRequest(HTTPRequest)
Line 277 of Director.php
* Director::handleRequest(HTTPRequest,Session)
Line 121 of Director.php
* Director::direct(/dev/build)
Line 118 of main.php

Your advice and help appreciated.

Thanks

Daniel

Avatar
banal

Community Member, 901 Posts

20 June 2009 at 9:33pm

Are you running this on a Linux Server? Keep in mind that *nix is usually case-sensitive, so the file should be named HomePage.php and not homepage.php... Not sure if this causes your issue though. But it's worth a try.

Go to Top