Giter VIP home page Giter VIP logo

Comments (11)

rizrob66 avatar rizrob66 commented on August 22, 2024

:-)

from yii2-settings.

arisk avatar arisk commented on August 22, 2024

Hi. Could you paste a code sample?

from yii2-settings.

rizrob66 avatar rizrob66 commented on August 22, 2024

The code is very simple:
Form:
` 'set-calendario-form', 'type' => ActiveForm::TYPE_HORIZONTAL,]); ?>

field($model, 'inizio_pre_semina', [ 'addon' => ['prepend' => ['content'=>'']]])->hint('formato gg-mm (Es. 03-02)') ?> field($model, 'percentuale_pre_semina', [ 'addon' => ['prepend' => ['content'=>'%']]]) ?>
    <?= Html::submitButton('Salva', ['class' => 'btn btn-success']) ?>
`

model:
`<?php
namespace app\models;
use Yii;

class calendario extends \yii\base\Model {
public $inizio_pre_semina,
$percentuale_pre_semina;

public function rules()
{
    return [ 
        [['inizio_pre_semina', 'percentuale_pre_semina', 
               ],  'string'],
    ];
}

...
`
The field percentuale_pre_semina in the model is string
if you insert a string like "pippo" the element was saved correctly
if you insert 10 (number) the error

PHP Recoverable Error – yii\base\ErrorException
Object of class stdClass could not be converted to string

the type of element is object and not string

from yii2-settings.

arisk avatar arisk commented on August 22, 2024

You haven't given any code that's used by the settings component.

from yii2-settings.

rizrob66 avatar rizrob66 commented on August 22, 2024

I did not understand what you mean, however, I'll write down all the code below. If I forgot something let me know

SiteController.php
.... 'calendario-settings' => [ 'class' => 'pheme\settings\SettingsAction', 'modelClass' => 'app\models\calendario', //'scenario' => 'site', // Change if you want to re-use the model for multiple setting form. 'viewName' => 'calendario-settings' // The form we need to render ],

app\model\calendario.php
`<?php

namespace app\models;

use Yii;

class calendario extends \yii\base\Model {
public $inizio_pre_semina,
$percentuale_pre_semina;

public function rules()
{
    return [ 
        [['inizio_pre_semina', 'percentuale_pre_semina', 
          ],  'string'],
    ];
}

public function fields()
{
        return ['inizio_pre_semina','percentuale_pre_semina', 
          ];
}

public function attributes()
{
        return ['inizio_pre_semina','percentuale_pre_semina', 
          ];
}

public function attributeLabels()
{
return [
'inizio_pre_semina' => 'Inizio pre-semina',
'percentuale_pre_semina' => '% pre-semina',
];
}
public function attributeHints()
{
return [
'inizio_pre_semina'=>'formato gg-mm (Es. 15-03) Inserire solo il segno meno (-) per il primo giorno utile.',
];
}

}
view\site\calendario-settings.php<?php

use yii\helpers\Html;

use kartik\widgets\ActiveForm;
//use yii\helpers\ArrayHelper;
//use kartik\select2\Select2;

//use app\models\Scelte;
//use app\models\Banche;
use kartik\icons\Icon;

$icon = Icon::show('settingsthree-gears', [], Icon::WHHG);
$this->title = 'Settaggio paramenti calendario';
$this->params['breadcrumbs'][] = $this->title;

?>

title) ?>

'set-calendario-form', 'type' => ActiveForm::TYPE_HORIZONTAL,]); ?> field($model, 'inizio_pre_semina', [ 'addon' => ['prepend' => ['content'=>'']]])->hint('formato gg-mm (Es. 03-02)') ?> field($model, 'percentuale_pre_semina', [ 'addon' => ['prepend' => ['content'=>'%']]]) ?>
    <?= Html::submitButton('Salva', ['class' => 'btn btn-success']) ?>
`

from yii2-settings.

arisk avatar arisk commented on August 22, 2024

Since you're using your own setting model you should configure that in the settings component and implement SettingInterface.

from yii2-settings.

rizrob66 avatar rizrob66 commented on August 22, 2024

Sorry but I do not understand what you mean. I followed the example provided in the documentation.
Please could you give me an example of:
How should i configure it in the component?
How I should implement SettingInterface?

This is a new thing that did not have to be done in the past, however, in the documentation is not described.

from yii2-settings.

rizrob66 avatar rizrob66 commented on August 22, 2024

:-)

from yii2-settings.

arisk avatar arisk commented on August 22, 2024

http://www.yiiframework.com/doc-2.0/guide-concept-configurations.html#configuration-files

https://secure.php.net/manual/en/language.oop5.interfaces.php

from yii2-settings.

dox07 avatar dox07 commented on August 22, 2024

Hi there! I had same problem some time ago. I have resolved like that: add filter rule for field in model custom form. For example:

class SettingsSendPaymentForm extends Model
{
public $isSendAutoPaymentToClient;

public function rules()
{
    return [
        [['isSendAutoPaymentToClient'], 'integer'],
        [['isSendAutoPaymentToClient'], 'filter', 'filter' => 'intval'],
    ];
}

In this way variable convert to integer type and when run setSettings function gettype return appropriate type of attribute. Thanks

from yii2-settings.

mohdqasim98 avatar mohdqasim98 commented on August 22, 2024

Having same issue ,
Tried adding filter => 'floatval' , but it didn't solved the problem.
@arisk , can you please explain your answer ?

from yii2-settings.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.