I have a function in a controller that when executed, check for existence of a record in a table and returns that record. This function is used as validation of a model inside the same controller. For example:
public function somethingValidate() {
$someVariable = SomeTable::find()->where(['some_id' => $someVariable])->one();
if ($model) {
return $model;
} else {
return false;
Here is the validation part of controller:
public function actionSave() {
$model = new TestModel() {
if ($this->somethingValidate()) {
try {
--- REST OF THE CODE ---
How can i now, pass $someVariable variable into a TestModel and manipulate the data either on save or beforeSave.
Any assistance is greatly appreciated.
$modelthere? Where is$someVariabletaken from?$modelis an actual model being saved with RESTful call, the$someVariableis taken from different table, different model and is used only for validation. If record exists, there is a id field referenced in$modeltable, where I need to save$someVariable->idDue to the nature of the project, I'm unable to provide better code example, sorry.