Internal Server Error after adding CMS fields in php file

I have created for the template and Homepage.php for the page type and after adding some codes to add a field in the php file, i am getting an internal server error message that pops up in a small window at the top right corner of the page and i also couldn’t get to the edit mode nor preview mode of the admin page.

Already flushed the cache and run dev/build also but doesnt work.


Make sure you have got
in your .env file.
When the Internal Server Error box pops up, refresh the page and you should get an error notice.

Actually, on looking at your code, you haven’t got a use statement at the top of the page for the HtmlEditorField. Try adding:
use SilverStripe\Forms\HTMLEditor\HtmlEditorField
at the top of the page

1 Like

i have done adding SS_ENVIRONMENT_TYPE=“dev” in the .env file in the root directory but this is still what i got after getting the error message in the admin page and refreshing the page.

below is what contains the .env file

I have flushed the cache and run dev/build as well but it didnt make any changes when displaying the error.

As per your 2nd instruction, i have added use SilverStripe\Forms\HTMLEditor\HtmlEditorField at the top of the page below php this is what i get.

below is my Homepage.php file

From the PHP errors it looks like you might be running an earlier version of PHP than one of your dependencies requires. If you installed SilverStripe with Composer you might want to check that your shell and your web server use the same version of PHP. Composer uses the shell version of PHP so if that doesn’t match your server version, you could end up installing unsuitable deps as Composer would be misinformed about what version of PHP you’re using. To check the version of PHP used by your server you can use phpino() and for the shell I think it’s php -v.

1 Like

Sorry for being dumb at this but where should i run those codes? I have the latest wamp server installed and below are the list of versions im running on my pc.


The second error is a common php error. ‘unexpected…’ means you’ve forgotten a character, usually on the previous line. In this case you’ve forgotten the semi-colon ( ; ) after the use statement.

1 Like

Oh yeah, that does look right. It would be nice if the call stack pointed to Homepage.php!

1 Like

I am new to php and still learning the basics as i am a designer not a programmer. I just didnt know that it requires adding that statement. Upon watching the tutorial, the statement "use SilverStripe\Forms\HTMLEditor\HtmlEditorField;" was not included in the code. How was he able to make it run without the statement? Also, what is the purpose of it? I’m planning to add a field for the image background as well so i’m not sure what should be the statement to be used upon adding ImageField or UploadField? I have been trying to do some research of my own regarding statements to avoid asking simple questions but i couldnt find any on the SS website.

Here is how my code looks like. Now, After adding the ImageField and running dev/build, i am getting a internal server error again on the cms page. I am already in dev mode on my .env file but the exact error on the line doesnt show up when i refresh the page.

Thank you for sharing those good info.

Now that i have changed my IDE to Sublime to get those namespaces. I still can’t get it to work. The UploadField is the one that i recently added because I want an image for background. I made sure that correct namespaces are there but still it gives me an internal server error with no details. Am i missing something? Are the namespaces for UploadField incorrect? I’m already in dev mode on my .env file

If you were watching (rather than reading) a lesson, then you were probably looking at a SilverStripe 3 lesson, not a SilverStripe 4 one. The SS3 lessons are available as videos, it looks like SS4 lessons haven’t been recorded yet and are only available as text articles. I wouldn’t be surprised if they don’t get turned in to videos as updating videos every time SilverStripe gets updated must be quite laborious.

SilverStripe 3 code doesn’t generally make use of namespaces, everything is in the global space, so you don’t need to include use statements. SS4 uses namespacing everywhere, so you have to do a little extra work when referring to class names.

You might want to check out this link for a primer on namespacing:

Also, you can make your life easier by installing a plugin for your editor that can automatically write your use statements. Here’s an example for VSCode: PHP Namespace Resolver - Visual Studio Marketplace

1 Like

Only other thing I can see in your code is in the $has_one array.

In SS4, instead of the classname string, you should use Image::class (no quotes). Same for any external class. You can also use square brackets instead of array() declaration.

So it should be:
private static $has_one = [
‘HomepageBackground’ => Image::class

1 Like

Thank you. You saved my life!