Comments (11)
:-)
from yii2-settings.
Hi. Could you paste a code sample?
from yii2-settings.
The code is very simple:
Form:
` 'set-calendario-form',
'type' => ActiveForm::TYPE_HORIZONTAL,]); ?>
<?= 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.
You haven't given any code that's used by the settings component.
from yii2-settings.
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.
Since you're using your own setting model you should configure that in the settings component and implement SettingInterface
.
from yii2-settings.
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.
:-)
from yii2-settings.
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.
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.
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)
- Exception on getting empty value which was saved as an object in db HOT 13
- Unable to locate message source for category 'extensions/yii2-settings/settings'. HOT 6
- Migration Fails with Exception: SQLSTATE[42000]: Syntax error or access violation: 1071 HOT 1
- How to seed settings HOT 6
- Settings cache problem HOT 6
- Custom form and upload image HOT 1
- Sort list alphabetically
- Invalid type when set type is "email" HOT 2
- Tag a new release HOT 1
- Descriptions for settings
- Tag 0.5 (stable) HOT 1
- migratoin error HOT 8
- Empty settings input fields saved as object HOT 11
- Using with sqlite
- please make a stable release HOT 1
- Update this extension for new version of Yii framework(2.0.14) HOT 3
- Object of class stdClass could not be converted to string
- Problem in editable save state
- problem save
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-settings.