Php 通过在OctoberCMS中添加配置文件不呈现选项卡或新添加的字段来扩展用户插件

Php 通过在OctoberCMS中添加配置文件不呈现选项卡或新添加的字段来扩展用户插件,php,laravel,laravel-4,octobercms,Php,Laravel,Laravel 4,Octobercms,我已经完成了屏幕上的所有步骤,但由于某些原因,我看不到“配置文件”选项卡和新添加的字段。因为我使用了第二种方法,简单的方法,这就是我所做的: 在Alomicuba名称空间下创建插件和模型等 创建并对文件进行必要的更改,如视频中所述: Plugin.php <?php namespace Alomicuba\Profile; use System\Classes\PluginBase; use RainLab\User\Models\User as UserModel; use Rai

我已经完成了屏幕上的所有步骤,但由于某些原因,我看不到“配置文件”选项卡和新添加的字段。因为我使用了第二种方法,简单的方法,这就是我所做的:

  • 在Alomicuba名称空间下创建插件和模型等
  • 创建并对文件进行必要的更改,如视频中所述:

    Plugin.php
    
    <?php namespace Alomicuba\Profile;
    
    use System\Classes\PluginBase;
    use RainLab\User\Models\User as UserModel;
    use RainLab\User\Controllers\Users as UsersController;
    
    /**
     * Profile Plugin Information File
     */
    class Plugin extends PluginBase
    {
        public $requires = ['RainLab.User'];
    
        /**
         * Returns information about this plugin.
         *
         * @return array
         */
        public function pluginDetails()
        {
            return [
                'name'        => 'Profile',
                'description' => 'Add extra functionalities for Alomicuba WS by extends RainLab User',
                'author'      => 'DTS',
                'icon'        => 'icon-users'
            ];
        }
    
        public function boot()
        {
            UserModel::extend(function($model){
                $model->hasOne['profile'] = ['Alomicuba\Profile\Models\Profile'];
            });
    
            UsersController::extendFormFields(function ($form, $model, $context){
                if ($model instanceof UserModel)
                    return;
    
                $form->addTabFields([
                    'pinCode' => [
                        'label' => 'PIN',
                        'tab' => 'Profile'
                    ],
                    'phone2' => [
                        'label' => 'Teléfono (2)',
                        'tab' => 'Profile'
                    ],
                    'phone3' => [
                        'label' => 'Teléfono (3)',
                        'tab' => 'Profile'
                    ],
                    'phone4' => [
                        'label' => 'Teléfono (4)',
                        'tab' => 'Profile'
                    ]
                ]);
            });
        }
    }
    
    add_profiles_fields_to_user_table.php
    
    <?php namespace Alomicuba\Profile\Updates;
    
    use Schema;
    use October\Rain\Database\Updates\Migration;
    
    class AddProfilesFieldsToUserTable extends Migration
    {
    
        public function up()
        {
            Schema::table('users', function($table)
            {
                $table->integer('pinCode')->unsigned();
                $table->dateTime('pinCodeDateTime');
                $table->integer('phone2')->unsigned()->nullable();
                $table->integer('phone3')->unsigned()->nullable();
                $table->integer('phone4')->unsigned()->nullable();
            });
        }
    
        public function down()
        {
            $table->dropDown([
                'pinCode',
                'pinCodeDateTime',
                'phone2',
                'phone3',
                'phone4'
            ]);
        }
    }
    
    version.yaml
    1.0.1: First version of Profile
    1.0.2:
        - Created profiles table
        - create_profiles_table.php
        - add_profiles_fields_to_user_table.php
    
    Profile.php (Model)
    <?php namespace Alomicuba\Profile\Models;
    
    use Model;
    
    /**
     * Profile Model
     */
    class Profile extends Model
    {
        /**
         * @var string The database table used by the model.
         */
        public $table = 'alomicuba_profile_profiles';
    
        /**
         * @var array Relations
         */
        public $belongsTo = [
            'user' => ['RainLab\User\Models\User']
        ];
    
    
        // This method is not need anymore since I'll use the second approach
        public static function getFromUser($user)
        {
            if ($user->profile)
                return $user->profile;
    
            $profile = new static;
            $profile->user = $user;
            $profile->save();
    
            $user->profile = $profile;
    
            return $profile;
        }
    }
    
    Plugin.php
    
    我已经在我的机器上测试了你的代码,你需要编写

    $require
    而不是plugin.php中的
    $requires

    请检查文件

    当为UserController调用extendFormFields()方法时,您需要指定只扩展UserModel的字段,而不扩展其他字段

    if (!$model instanceof UserModel)
        return;
    
    因此plugin.php代码如下所示

    <?php namespace Alomicuba\Profile;
    
    use System\Classes\PluginBase;
    use RainLab\User\Models\User as UserModel;
    use RainLab\User\Controllers\Users as UsersController;
    
    /**
     * Profile Plugin Information File
     */
    class Plugin extends PluginBase
    {
        public $require = ['RainLab.User'];
    
        /**
         * Returns information about this plugin.
         *
         * @return array
         */
        public function pluginDetails()
        {
            return [
                'name'        => 'Profile',
                'description' => 'Add extra functionalities for Alomicuba WS by extends RainLab User',
                'author'      => 'DTS',
                'icon'        => 'icon-users'
            ];
        }
    
        public function boot()
        {
            UserModel::extend(function($model){
                $model->hasOne['profile'] = ['Alomicuba\Profile\Models\Profile'];
    
            });
    
            UsersController::extendFormFields(function ($form, $model, $context){
                if (!$model instanceof UserModel)
                    return;
    
                $form->addTabFields([
                    'pinCode' => [
                        'label' => 'PIN',
                        'tab' => 'Profile'
                    ],
                    'phone2' => [
                        'label' => 'Teléfono (2)',
                        'tab' => 'Profile'
                    ],
                    'phone3' => [
                        'label' => 'Teléfono (3)',
                        'tab' => 'Profile'
                    ],
                    'phone4' => [
                        'label' => 'Teléfono (4)',
                        'tab' => 'Profile'
                    ]
                ]);
            });
        }
    }
    

    我认为在laravel的最新版本中,
    dropDown
    已重命名为
    dropColumn
    Schema::table('users', function($table)
    {
            $table->dropDown([
                'pinCode',
                'pinCodeDateTime',
                'phone2',
                'phone3',
                'phone4'
            ]);
    }