Jump to content

[SOLVED] Pass data to custom user method


gebeer
 Share

Recommended Posts

Hello,

I want to add a custom method to the user object and need to pass some data ( an array called $params) to the method when I call it.

I will call the method like this

$user->saveprofile($params);

The method takes that data and saves it to a user profile page.

Only I don't know how to pass that data to my custom method.

This might be a silly question. Please forgive me, but I am fairly new to OOP and PW modules/hooks development.

This is what I have so far (taken off examples from here):

    public function init() {
        // init() is called when the module is loaded.
        $this->addHook('User::saveprofile', $this, 'UserSaveProfile'); 
    }

    public function UserSaveProfile($event) { //how to pass my $params array to this method 

        // Get the user object
        $user = $event->object;

        // get user data - this is where I am stuck 
        $userData = 

        //  condition and actions
        if($user->hasRole("frontend")) {
            
            //create and save user profile page

            $this->message("Userprofile page for user " . $user->name . "has been created");
        }
    }

I tried to find examples of how to do that but could not find anything related in the forum.

Any help would be appreciated. Thank you.

Link to comment
Share on other sites

Thank you both, LostKobrakai and Soma !

I call my custom method with

$user->saveprofile($params)

and can access the data in my method with

$userData = $event->arguments(0);

PS: Missing the Solved Button

Link to comment
Share on other sites

I would like to mark this as solved. But the "Mark Solved" Button is missing.  I just used it on another thread of mine. But here it is not available. I opened the thread, so I should see this button?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...