Open rizrob66 opened 8 years ago
Hi Roberto. There's an example of how to use the settings action in the readme file. If you have any problems with those instructions please show me what you have so far and I'll try to help you get it working.
Thanks arisk, I work with basic and made the model in models\AziendaSettings.php directory:
<?php
namespace app\models;
use Yii;
class AziendaSettings extends \yii\base\Model {
public $titolare, $telefono;
public function rules()
{
return [
[['titolare', 'telefono'],
];
}
public function fields()
{
return ['titolare', 'telefono'];
}
public function attributes()
{
return ['titolare', 'telefono'];
}
}
in views\site\azienda-settings.php
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(['id' => 'azienda-settings-form']); ?>
<?= $form->field($model, 'titolare') ?>
<?= $form->field($model, 'telefono') ?>
<?php ActiveForm::end(); ?>
in controllers\SiteController.php:
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
'azienda-settings' => [
'class' => 'pheme\settings\SettingsAction',
'modelClass' => 'app\models\AziendaSettings',
//'scenario' => 'site', // Change if you want to re-use the model for multiple setting form.
'viewName' => 'azienda-settings' // The form we need to render
],
];
}
when I try index.php?r=site/azienda-settings There is no submit button and I can't see the actual value of the varable azienda.titolare and azienda.telefono . You Settings is very usefull, please help me to complete.
I think that you forgot to add submit button in your view:
<?php $form = ActiveForm::begin(['id' => 'social-service-form']); ?>
<?= $form->field($model, 'twitter') ?>
<?= $form->field($model, 'google') ?>
<?= $form->field($model, 'facebook') ?>
<?= $form->field($model, 'youtube') ?>
<?= $form->field($model, 'linkedin') ?>
<?= $form->field($model, 'pinterest') ?>
<?= $form->field($model, 'vimeo') ?>
<?= $form->field($model, 'instagram') ?>
<?= $form->field($model, 'vk') ?>
<?= $form->field($model, 'ok') ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
thanks demogorgorn, I add the submit button as you suggester and: Invalid Configuration – yii\base\InvalidConfigException Unable to locate message source for category 'extensions/yii2-settings/settings'. ..... Module::t('settings', '{attribute} "{value}" already exists for this section.') :-(
Have a look at this comment to configure your translations correctly. https://github.com/phemellc/yii2-settings/issues/51#issuecomment-221190859
Yesss!!!!!!! it works!!!!! Thank you very much indeed! :-)
You're welcome :)
I can not make a custom form.
PHP Recoverable Error – yii\base\ErrorException Object of class stdClass could not be converted to string
Controller:
Model:
print_r($model) in view:
UPDATE: If you just save numbers in the text box, then this error occurs. If the text field, then all is well.
If you just save numbers in the text box, then this error occurs. If the text field, then all is well.
having the same issue. Any fix ?
Hi, I tried to use SettingAction to make a custom form to handle a setting category. There are several things I did not understand, so it doesn't work. Could you please provide an fully working example? thanks Roberto