1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Dealing with User Management

Discussion in 'XenForo Development Discussions' started by Jeremy, Oct 7, 2010.

  1. Jeremy

    Jeremy XenForo Moderator Staff Member

    I am writing an add on that deals with user information. I want to lean on XenForo_DataWriter_User's _verifyUsername() function, but since it is protected, I cannot call XenForo_DataWriter_Users::_verifyUsername(); within my _verifyUsername() function, but I really don't want to rewrite / distribute the code 'as my own.' Should I extend this class, even though this is basically the only function I require from the XenForo_DataWriter_User class, so, best option here? My post, pre, and save functions are all separate, because it deals with my own table (well, ok, save will call XenForo_DataWriter_User to update the username eventually).
     
  2. Jeremy

    Jeremy XenForo Moderator Staff Member

    OK, I see that I can maybe use _publish() and _getPermissionModel() as my add on uses permissions and it'd be nice to maybe publish the results?
     
  3. Deceptor

    Deceptor Active Member

    Does your method only need to be used by your modification? If so I'd extend the class and create a new method like "_myVerifyUsername()" which calls the parent and then your validation:

    PHP:
    protected function _myVerifyUsername($username)
    {
        if (!
    parent::_verifyUsername($username))
        {
            return 
    false;
        }

        
    // your checks here

        
    return true;
    }
     
  4. Jeremy

    Jeremy XenForo Moderator Staff Member

    Basically, I just want to mimic that functionality. So, basically _myVerifyUsername = _verifyUsername. Hence the choice to extend that class. I think that might be the best choice, but not sure with this whole MVC thing.
     
  5. Deceptor

    Deceptor Active Member

    I updated my previous post, I had some dumb code (didn't return false if the parent came back false). Extending then calling the parent seems like the best approach in my opinion :)

    If you don't want to add anything to the method, you should still be able to call _verifyUsername() from your extended class as normal, no?
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    I should be able to, but I defined a _usernameRequestVerifyUsername($username) because I am using the array('$this', 'functionName') setup for verification, so... I just used that and...
    PHP:
        /**
        * Verifies the username against administrator defined criteria.
        *
        * @return boolean
        */
        
    protected function _usernameRequestVerifyUsername($username)
        {
            return 
    parent::_verifyUsername($username);
        }
     
  7. Deceptor

    Deceptor Active Member

    Gotcha, well inside the class public/protected visibility is accessible (protected is locked to outside scope), only private visibility is locked to extended classes (and outside scope). You might wanna take a look at this for more info on visibility: http://php.net/manual/en/language.oop5.visibility.php
     
  8. Jeremy

    Jeremy XenForo Moderator Staff Member

    Yeah, I got those. :) I just am not sure how to use parent:: within this code:
    PHP:
                    'requested_name'
                        
    => array('type' => self::TYPE_STRING'required' => true'maxLength' => XenForo_Application::get('options')->usernameLengthMax'verification' => array('$this''_usernameRequestVerifyUsername'), 'requiredError' => 'please_enter_valid_name'),
    And I am not feeling like looking it up, so I made my own function in the $this class, to call the parent::.
     
  9. Jeremy

    Jeremy XenForo Moderator Staff Member

    Nope, I need my username verification, there's one or two more verifications I want to include... Solves that problem. :p Now, I just gotta figure out error messages. Does $this->errors[] work?
     
  10. Deceptor

    Deceptor Active Member

    It's stored in the array _errors under the DataWriter class, you can access the array via: $class->getErrors() :)
     

Share This Page