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.


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

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

Adding user fields + Register function + Admin area SLOW

Go to End

18 Posts   4995 Views


15 October 2008 at 12:31am (Last edited: 15 October 2008 6:53pm), Community Member, 36 Posts

Hey there!

1. How would you go about adding fields to the user database, for example if you wanted to add phone numbers or addresses?
/silverstripe/sapphire/security/Member.php seems to be something to do with it, just wondering why all of the fields aren't visible in the Admin area

2. Is there a register function in SilverStripe?
- Basically, can you use SilverStripe for a 'members area'?
/silverstripe/sapphire/security/Member.php says :
Send signup, change password or forgot password informations to an user
... function sendInfo - not sure if that is anything

3. Also, whenever I access the admin area, it takes ages to load compared to the demo on this site.

4. Where would you change the site title and tagline?
Edit: /silverstripe/themes/blackcandy/templates (for that theme, think its right)

5. What is the difference between the theme folder, the mysite folder and the tutorial folder?
- Can I delete tutorial? What is mysite about?



15 October 2008 at 6:53pm Community Member, 36 Posts



15 October 2008 at 8:37pm Forum Moderator, 5511 Posts

If you havent read the tutorials then I suggest you do. Im pretty sure these go into more detail for you. I'll start with the easiest things first

5) tutorial is a complete project (PHP code, css, templates) which is there if you want to follow the tutorials with the code as reference. If you do not want to use the tutorial theme (eg you have gone through the tutorials) then delete it.

Mysite folder is where you should keep all your PHP code. There is still the 'templates', 'css' folders in mysite as before we had a theming engine you used to keep all your project info in mysite, Now the recommended way is to keep PHP code in mysite/code/ and all your templates, css, images in your own custom theme inside the 'themes' folder. These differences will be tidied up and documented better pretty soon.

4) Correct, you would need to edit the template file in themes/blackcandy/templates

3) Are you trying to access it on a local website or on a webserver? SilverStripe is quite resource intensive. Our demo site is running mod_cache and gzipping components (which are both recommended for sites, not just SS ones).

2) Josh is in the process of making a 'register' module / tutorial for users to follow. Its quite simple but you have to understand the concepts first. Have a look at the third tutorial and also checkout the forum module - currently the only module with a user registation system. That is an example anyway. Its a bit more complicated then what you probably need but as a reference try using that. If you have any questions feel free to ask.

1) To add fields to a member you wouldnt edit that file as when you went to upgrade SS your changes would be lost.

What you need to do instead is create your own member class. Again for this have a look at the forum Module (note the ForumRole - which defines the Forum member, you need to base it off this.)


15 October 2008 at 9:08pm Community Member, 36 Posts

Thanks heaps! I ran through the tutorials before but I probably need to do them again - the concepts are quite tricky for me.

I have some PHP code that I was working on before I heard about SilverStripe - but it needed a login system.

How would I go about retrieving the ID of the person logged in and matching that ID up with a separate table in my database to retrieve information?

ie. David is logged in with ID 1. Old PHP code knows that logged in user has an ID of 1, matches it to the corresponding row in another table and retrieves information from that table.

Then how would I go about incorporating my old PHP code?
- Would I put it in the controller class of a template page if the code was only needed in that one page?
- Also, if in my old code I had a 'database.php' which had all of the database functions inside it, where would I put it in SS where every page could access it?

In PHP, if you want to access an array, you can do $array['1'].
Looking in some PHP code, I saw something like $array->1 - would that be right? Unfortunately google doesn't search special characters like "->" which can be frustrating.


15 October 2008 at 9:22pm (Last edited: 15 October 2008 9:23pm), Forum Moderator, 5511 Posts

You can do this in your PHP


This returns the whole 'Member' object or null if no ones logged in. The benefit of getting the whole object is that you can do something like Member::currentUser()->Email or something to get the Email address or you can call any methods etc.

As well as that you can do


Which returns the ID of the currently logged in member, If any.

As for how to incorporate old code, and the where to put code debate - we are planning on updating the docs to make this clearer but basically I suggest putting it in the Controller section.

I put it in SS where every page could access it?

In your root Page.php. This is your base Page file that comes standard with the install. If you look at tutorial 2 you can see 'ArticlePage' extends Page. So you should make all your custom pages extend page (which means ArticlePage has everything Page has put simply).

In PHP, if you want to access an array, you can do $array['1'].
Looking in some PHP code, I saw something like $array->1 - would that be right?

This is only in some cases. If you do $member->Email SS automatically looks for the database field 'Email' on the 'Member' table (or whatever class $member is). If you want to use arrays in your php functions then it is the same. The only time you use the $var->Field syntax is when $var is an 'Object' eg this example

$page = new Page(); // creates a blank page
$page->Title = "Hi World"; // $page->Title refers to the Database field 'Title' on the 'Page' class


15 October 2008 at 9:52pm Community Member, 36 Posts

Do you mean, by root Page.php, ./silverstripe/mysite/code/Page.php?

Also, for accessing the database with my own tables should I use my previous code:


// Initialise mySql database connection
$conn = mysql_connect($dbLocation, $dbUsername, $dbPassword);

// Check if connection succeeded
if (!$conn) {
echo "Unable to connect to the database: " . mysql_error();

// Select database 'cnzcom_medcheck' and check if succeeded
if (!mysql_select_db($dbDatabase)) {
echo "Unable to select $dbDatabase: " . mysql_error();

And should I use require("constants.php") or is there something else I can do?

Or... is there database accessing feature in SS? To do things like connect and run SQL?


15 October 2008 at 11:37pm Forum Moderator, 5511 Posts

Yes that is the correct file.

If the db you want to get the data from is the same as your ss install db then it does all that for you. See or use DataObject::get() calls .


15 October 2008 at 11:56pm Community Member, 36 Posts

Looking at the datamodel I see this:

Each database-table maps to a php-class
Each database-row maps to a php-object
Each database-column maps to a property on a php-object

I'm guessing I shouldn't tamper with the database by itself, I should let the /db/build?flush=1 do that.

Should I then create something like this and place this somewhere:

class UserInfo extends something? {

static $db = array(
'Field I want in the database' => 'type'

static $has_many = array(


Then it will create a UserInfo table for me?

Then I can use DataObject to get the fields?

Go to Top