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

Adding user fields + Register function + Admin area SLOW


Go to End


18 Posts   6554 Views

Avatar
Piklets

Community Member, 36 Posts

15 October 2008 at 12:31am

Edited: 15/10/2008 6:53pm

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?

Thanks,
David

Avatar
Piklets

Community Member, 36 Posts

15 October 2008 at 6:53pm

bump

Avatar
Willr

Forum Moderator, 5523 Posts

15 October 2008 at 8:37pm

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 Page.ss 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.)

Avatar
Piklets

Community Member, 36 Posts

15 October 2008 at 9:08pm

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?

Also...
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.

Avatar
Willr

Forum Moderator, 5523 Posts

15 October 2008 at 9:22pm

Edited: 15/10/2008 9:23pm

You can do this in your PHP

Member::currentUser(); 

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

Member::currentUserID();

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

Avatar
Piklets

Community Member, 36 Posts

15 October 2008 at 9:52pm

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:

require("constants.php");

// 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();
die();
}

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

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?

Avatar
Willr

Forum Moderator, 5523 Posts

15 October 2008 at 11:37pm

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 http://doc.silverstripe.com/doku.php?id=sqlquery or use DataObject::get() calls .

Avatar
Piklets

Community Member, 36 Posts

15 October 2008 at 11:56pm

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