<?php
class Photo extends ActiveRecord
{
public $types;
public static function create($file, $title, $alt, $type): self
{
$photo = new static();
$photo->file = $file;
$photo->title = $title;
$photo->alt = $alt;
// set types property
$photo->types = $type;
return $photo;
}
public function behaviors()
{
print_r($this->types);
return [ 'some behavior attributes' ];
}
}
note: your behaviors might be attached before you call create so be careful yii provides access to the context object through $this->owner property inside the behavior allows you to access the owner object.