UTF-8 encodes the attributes of a model.

@param Model $model
@return Model
169948
public static function utf8EncodeModel(Model $model)
    {
        foreach($model->toArray() as $key => $value) {
            if (is_numeric($value) || !is_string($value)) {
                continue;
            }
            $model->$key = utf8_encode($value);
        }

        return $model;
    }
555900
protected function getFromCasts(Model $model, $key)
    {
        $casts = $this->getCasts($model);

        if (!isset($casts[$key])) {
            return '';
        }

        $cast = $casts[$key];

        foreach ($this->xTypeToCasts as $xType=>$casts) {
            if (in_array($cast, $casts)) {
                return $xType;
            }
        }

        return 'string';
    }
443991
protected function makeTranslatedDataFromModelData(array $model)
    {
        // translated model is sluggable if model is, but on translated property or column
        $sluggable = ($model['sluggable'] && array_get($model, 'sluggable_setup.translated'));

        return [
            'module'                => $model['module'],
            'name'                  => $model['name'] . config('pxlcms.generator.models.translation_model_postfix'),
            'table'                 => ! empty($model['table'])
                ? $model['table'] . snake_case(config('pxlcms.tables.translation_postfix', '_ml'))
                : null,
            'cached'                => $model['cached'],
            'is_translated'         => false,
            'is_translation'        => true,    // only true if it is a Translation model itself
            'is_listified'          => false,
            'order_by'              => [],
            // attributes
            'normal_fillable'       => $model['translated_attributes'],
            'translated_fillable'   => [],
            'hidden'                => [],
            'casts'                 => [],
            'dates'                 => [],
            'defaults'              => [],
            'normal_attributes'     => [],
            'translated_attributes' => [],
            'timestamps'            => null,
            // categories
            'categories_module'     => null,
            // relations
            'relations_config'      => [],
            'relationships'         => [
                'normal'   => [],
                'reverse'  => [],
                'image'    => [],
                'file'     => [],
                'checkbox' => [],
            ],
            // special
            'sluggable'       => $sluggable,
            'sluggable_setup' => $sluggable ? $model['sluggable_setup'] : [],
            'scope_active'    => false,
            'scope_position'  => false,
        ];
    }
187346
protected function getForeignKeyName(Model $model)
    {
        $table = $model->getTable();

        if (array_key_exists($table, $this->foreignKeyLookup)) {
            return $this->foreignKeyLookup[$table];
        }

        return Str::singular($table).'_id';
    }
161757
public function transform($value)
    {
        if (function_exists('mb_check_encoding')) {
            $isUtf8 = mb_check_encoding($value, 'UTF-8');
        } else {
            $isUtf8 = $this->checkUtf8Encoding($value);
        }

        return  $isUtf8 ? $value : utf8_encode($value);
    }
736484
protected function savePost($model, $modelsI18n)
    {
        $post = Yii::$app->request->post();//var_dump($post);exit;
        if (!$model->load($post)) return false;//var_dump($model->attributes);

        $this->timeCorrection($model, 'show_from_time');
        $this->timeCorrection($model, 'show_to_time');//var_dump($model->attributes);exit;
        
        $created = false;
        try {
            if ($model->save()) {
                $created = true;

                $model->imagefile = UploadedFile::getInstance($model, 'imagefile');
                if ($model->imagefile && $model->validate()) {                
                    $model->image = $this->saveImage($model);
                    if($model->image) $model->save(false, ['image']);
                }//var_dump($model->attributes);var_dump($model->errors);exit;

                $contentHelper = new $this->contentHelperClass;
                foreach($modelsI18n as $langCode => $modelI18n) {
                    if (!empty($post[$this->multilangFormName][$langCode])) {
                        $data[$this->multilangFormName] = $post[$this->multilangFormName][$langCode];
                        if ($modelI18n->load($data)) {
                            $modelI18n->lang_code = $langCode;
                            $modelI18n->news_id = $model->id;
                            $modelI18n->body = $contentHelper::beforeSaveBody($modelI18n->body);
                            $modelI18n->save();
                        }
                    }
                }
            }//var_dump($model->attributes);var_dump($model->errors);exit;
        } catch (DbException $e) {
            $msg = Yii::t($this->tcModule, 'Database save error');
            $msgFull = $msg . "<br />\naction=" . $this->action->uniqueId . "<br />\n" . $e->getMessage();
            Yii::error($msgFull);
            Yii::$app->session->setFlash('error', $this->module->params['showAdminSqlErrors'] ? $msgFull : $msg);
        }

        // back texts correction for visual editor
        if (!$created || $this->modelsHaveErrors($model, $modelsI18n)) {
            $modelsI18n = $model::correctI18nBodies($modelsI18n);
        }

        return $created;
    }
501040
private function getGroupKeyForModel(Model $model)
    {
        $key = "";

        foreach ($this->groups as $group) {
            $key .= $model[$group] . "|";
        }

        return $key;
    }
409185
public function save(Model $model)
    {
        $foreignKey = $this->getForeignKeyName();
        $parentKeyValue = $this->getParentKey();

        if (is_array($foreignKey)) { //Check for multi-columns relationship
            foreach ($foreignKey as $index => $key) {
                $model->setAttribute($key, $parentKeyValue[$index]);
            }
        } else {
            $model->setAttribute($foreignKey, $parentKeyValue);
        }

        return $model->save() ? $model : false;
    }
995618
public function process(Model $model)
    {
        $data = $model->getData();

        // Check if this is a possible callback.
        // We are not going to analyse this further, because modern systems
        // do not use these anymore.
        if (function_exists($data) === true) {
            $model->setIsCallback(true);
        }

        // Checking the encoding.
        $encoding = $this->pool->encodingService->mbDetectEncoding($data);
        if ($encoding === false) {
            // Looks like we have a mixed encoded string.
            // We need to tell the dev!
            $length = $this->pool->encodingService->mbStrLen($data);
            $strlen = 'broken encoding ' . $length;
            $model->addToJson(static::META_ENCODING, 'broken');
        } else {
            // Normal encoding, nothing special here.
            $length = $strlen = $this->pool->encodingService->mbStrLen($data, $encoding);
        }

        if ($length > 20) {
            // Getting mime type from the string.
            // With larger strings, there is a good chance that there is
            // something interesting in there.
            $model->addToJson(static::META_MIME_TYPE, $this->bufferInfo->buffer($data));
        }

        // Check, if we are handling large string, and if we need to use a
        // preview (which we call "extra").
        // We also need to check for linebreaks, because the preview can not
        // display those.
        if ($length > 50 || strstr($data, PHP_EOL) !== false) {
            $cut = $this->pool->encodingService->encodeString(
                $this->pool->encodingService->mbSubStr($data, 0, 50)
            ) . static::UNKNOWN_VALUE;

            $data = $this->pool->encodingService->encodeString($data);

            $model->setHasExtra(true)
                ->setNormal($cut)
                ->setData($data);
        } else {
            $model->setNormal($this->pool->encodingService->encodeString($data));
        }

        return $this->pool->render->renderSingleChild(
            $model->setType(static::TYPE_STRING . $strlen)
                ->addToJson(static::META_LENGTH, $length)
        );
    }
285931
public function getGroupName(Model $model) {
		$modelNamePlural = $this->getModelNamePlural($model);
		$groupNameCamel = Inflector::humanize(Inflector::underscore($modelNamePlural));
		$groupName = mb_ucfirst(mb_strtolower($groupNameCamel));

		return $groupName;
	}
256903
public function getAttribute($key, $model = false)
    {
        if (!$key) {
            return;
        }

        if (!$model) {
            $model = $this->model;
        }

        $formattedKey = str_replace('.', '_', $key);

        if ($this->hasGetAccessor($formattedKey)) {
            $method = 'get'.Str::studly($formattedKey).'Attribute';

            return $this->{$method}($model);
        }

        if ($this->hasGetAccessor($key)) {
            $method = 'get'.Str::studly($key).'Attribute';

            return $this->{$method}($model);
        }

        if ($this->hasRelatedKey($key, $model)) {
            return $this->relatedKey($key, $model);
        }

        return $model->getAttribute($key);
    }
1031363
private function generateModel($model){
        if(is_object($model))
            Session::set(md5(Request::getArea().Request::getController().Request::getAction()), base64_encode(get_class($model)));
    }
466557
private static function getNameAttribute($model) {
        $attributes = $model->getConnection()->getSchemaBuilder()->getColumnListing($model->getTable());
        $compares = config("sirgrimorum.crudgenerator.probable_name");
        foreach ($compares as $compare) {
            if (in_array($compare, $attributes)) {
                return $compare;
            }
        }
        return $model->getKeyName();
    }
347539
protected static function encryptAttributes(Model $model)
    {
        foreach (static::getEncryptedAttributes() as $attribute) {
            try {
                $model->$attribute = static::getEncrypter()->encrypt($model->$attribute);
            } catch (EncryptException $e) {
            }
        }

        return $model;
    }
1136678
protected function setForeignAttributesForCreate(Model $model)
    {
        $foreignKey = $this->getForeignKeyName();
        $parentKeyValue = $this->getParentKey();
        if (is_array($foreignKey)) { //Check for multi-columns relationship
            foreach ($foreignKey as $index => $key) {
                $model->setAttribute($key, $parentKeyValue[$index]);
            }
        } else {
            parent::setForeignAttributesForCreate($model);
        }
    }
90496
protected function parseModel($model)
    {
        if (false === strpos($model, '\\')) {
            $path = explode('\\', static::class);
            array_pop($path);
            array_push($path, Db::parseName($model, 1));
            $model = implode('\\', $path);
        }

        return $model;
    }
485273
public function save(Model $model)
    {
        $model->setAttribute($this->getForeignKeyName(), $this->getParentKey());

        return $model->save() ? $model : false;
    }