This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

mesunil2010
mesunil2010

Hi Guys,

I am trying to get admin email setting into my plugin . What could be the easiest way ?

Thanks

LilEssam
LilEssam

Do you mean you're trying to get the email of the Superuser of the site?

Or you want to make a setting for your plugin so the plugin user can insert an Email you'll use in your plugin?

LilEssam
LilEssam

Well, If you mean you want to register a new setting for your plugin, You can just do it by defining registerSettings() method in your Plugin.php file.

Here's an example from one of my plugins.

public function registerSettings()
    {
        return [
            'settings' => [
                'label'       => 'Email Settings',
                'description' => 'Manage settings.',
                'category'    => 'Alshikh Settings',
                'icon'        => 'icon-cog',
                'class'       => 'Lilessam\Alshikhsettings\Models\Settings',
                'order'       => 500,
                'keywords'    => '',
                'permissions' => []
            ]
        ];
    }

The next step is to create a model in your Authorname\Pluginname\Models folder with Settings.php name. And here's an example.

<?php namespace Lilessam\Alshikhsettings\Models;

use Model;

class Settings extends Model
{
    public $implement = ['System.Behaviors.SettingsModel'];

    // A unique code
    public $settingsCode = 'lilessam_alshikh_settings';

    // Reference to field configuration
    public $settingsFields = 'fields.yaml';
}

As you can see you only need to assign settingsCode and settingsFields file which will be in a folder called Settings within your Settings Model Folder.

And inside your fields.yaml file you can define the form elements.

# ===================================
#  Form Field Definitions
# ===================================

fields:
    email:
        label: Email Address
        description: The Email which you want to receive emails to.

So, How to get the value of 'email' field from the settings? You can get it anywhere on your site by just calling the model settings using use authorname\pluginname\models\Settings.php

And then you can get the email field value using the following line:

$email = Settings::instance()->email;

If you didn't mean that please feel free to explain what you want to do and I'll provide a full explanation the best I can.

Thanks.

amjadiqbalkhanniazi28057
amjadiqbalkhanniazi28057

I got this error when i use above process

  Class 'Aaexchange\Currencyconverter\Models\Settings' not found

I have created model Settings in my plugins models but it is giving me this error

Last updated

1-4 of 4

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.