Pass Controller Variables into a Model I am using a Controller to get Variables from a field in my Plugin.
How and what would be the best way to pass and use them in other classes or my main plugin file.

I thought about using Sessions or passing them via URL Parameters, but i am not sure if thats the most convenient way.

Thats my controller:

use craft\web\Controller;

class SetUserController extends Controller {
    public function actionSubmitUser() {

        $request = \Craft::$app-&gt;getRequest();

        $dateTime = $request-&gt;getParam('dateTime');
        $user = $request-&gt;getRequiredParam('user');

    }
}  


e.g. in my main plugin file i would like to pass the variable to a function:

// check if commerce record for craft user exists
public function checkCommerceRecord($user) {
    return $this-&gt;customers-&gt;getCustomerByUserId($user);
}


Update:

I figured that i need to setup a module, however i cant save the variables into the module, getting Setting unknown property: wewereyoung\wfwplugin\models\WFWPluginModel::userId

Module:


namespace wewereyoung\wfwplugin\models;

use craft\base\Model;
use craft\validators\ArrayValidator;

class WFWPluginModel extends Model {

    public $setUser = [
        'userId',
        'timeDate'
    ];

    public function rules() {
        return [
            [
                [
                    'setUser'
                ],
                ArrayValidator::class
            ]
        ];
    }
}


Updated Controller:



namespace wewereyoung\wfwplugin\controllers;

use craft\web\Controller;
use wewereyoung\wfwplugin\models\WFWPluginModel;

class SetUserController extends Controller {
    public function actionSubmitUser() {

        $request = \Craft::$app-&gt;getRequest();

        $dateTime = $request-&gt;getParam( 'dateTime' );
        $userId   = $request-&gt;getParam( 'user' );

        $setUser            = new WFWPluginModel();
        $setUser-&gt;userId   = $userId;
        $setUser-&gt;dateTime = $dateTime;

    }
}
To simply pass the variables to your plugin or module use:

MyPlugin::getInstance()-&gt;checkCommerceRecord($user, $dateTime);


To pass to a service (see the Creating a Service section of the docs) use:

MyPlugin::getInstance()-&gt;myService-&gt;checkCommerceRecord($user, $dateTime);


To pass it with your model use:

$model = new WFWPluginModel(['setUser' =&gt; [$userId, $dateTime]]);

MyPlugin::getInstance()-&gt;myService-&gt;checkCommerceRecord($model);