Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Adding user fields + Register function + Admin area SLOW

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

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

Page: 1 2 3
Go to End
Author Topic: 4919 Views
  • Piklets
    Avatar
    Community Member
    36 Posts

    Adding user fields + Register function + Admin area SLOW Link to this post

    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

  • Piklets
    Avatar
    Community Member
    36 Posts
  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Adding user fields + Register function + Admin area SLOW Link to this post

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

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Adding user fields + Register function + Admin area SLOW Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Adding user fields + Register function + Admin area SLOW Link to this post

    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

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Adding user fields + Register function + Admin area SLOW Link to this post

    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?

  • Willr
    Avatar
    Forum Moderator
    5490 Posts

    Re: Adding user fields + Register function + Admin area SLOW Link to this post

    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 .

  • Piklets
    Avatar
    Community Member
    36 Posts

    Re: Adding user fields + Register function + Admin area SLOW Link to this post

    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?

    4919 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.