0

I would like to implement a list into backend controller for my users under a new tab.

https://ibb.co/fkAWFR (Add Tab Field)


UsersController::extendFormFields(function($form, $model, $context){
            if (!$model instanceof UserModel)
                return;
            if (!$model->exists)
                return;
            $form->addTabFields([
                'activity' => [
                    'tab' => 'Activity',
                    'type'  => 'partial',
                    'path' => '$/acme/plugin/controllers/viewedjobs/_viewed_jobs.htm'
                ]
            ]);
        });

https://ibb.co/ktHdvR (include this list)

My _viewed_jobs.htm partial looks like this:

listRender() ?>

Which throws an error about list behavior not being initialized. After some looking I found these posts: https://octobercms.com/forum/post/listcontroller-error-need-help

So I added

$this->asExtension('ListController')->index()
to the partial and now it displays my user list controller.

I would like to display a list for my ViewedJobs controller. I also watched the tutorial here: https://octobercms.com/support/article/ob-21 to create my list manually, however, the variables are not defined when I use this code.

I also tried creating a new list config under the Users plugin (which I know is not a best practice) but it throws and error about groups() method not found.

4

2 回答 2

2

您可以轻松地显示列表。

我假设您正在使用rain-lab 用户插件并且当前的UsersController是rain lab 的用户控制器

你有工作表并且用户和工作表之间有毫米关系

您需要将此代码放入插件的启动方法中

// first we extend users model with jobs relation
\RainLab\User\Models\User::extend(function($model) {
    $model->belongsToMany['jobs'] = [\Hardiksatasiya\Test\Models\Job::class, 'table' => 'hardiksatasiya_test_job_user'];
});

// we now extend users controller to add relation behavior
// also add relational configuration
// we are doing this with not destructive method
// so our extend will play nice to other's extends
\RainLab\User\Controllers\Users::extend(function($controller) {
    // Implement behavior if not already implemented
    if (!$controller->isClassExtendedWith('Backend.Behaviors.RelationController')) {
        $controller->implement[] = 'Backend.Behaviors.RelationController';
    }

    // Define property if not already defined
    if (!isset($controller->relationConfig)) {
        $controller->addDynamicProperty('relationConfig');
    }

    // Splice in configuration safely
    $myConfigPath = '$/hardiksatasiya/test/models/job/config_relation_for_users.yaml';

    $controller->relationConfig = $controller->mergeConfig(
        $controller->relationConfig,
        $myConfigPath
    );
});

// now your actual code for extending fields
\RainLab\User\Controllers\Users::extendFormFields(function($form, $model, $context){
    if (!$model instanceof \RainLab\User\Models\User)
        return;
    if (!$model->exists)
        return;
    $form->addTabFields([
        'jobs' => [
            'tab' => 'Activity',
            'type'  => 'partial',
            'path' => '$/hardiksatasiya/test/controllers/job/_user_job_relation.htm'
        ]
    ]);
});

关系配置 => config_relation_for_users.yaml

jobs:
  label: Jobs
  view:
    showCheckboxes: false
    toolbarButtons: false
    list: $/hardiksatasiya/test/models/job/columns.yaml

关系部分 => _user_job_relation.htm

<?= $this->relationRender('jobs') ?>

如果它不起作用,请发表评论

于 2017-12-13T17:33:58.353 回答
0

我继续使用关系管理器OctoberCMS 关系进行了工作

UsersController::extend(function($controller){         
        // Splice in configuration safely
        $myConfigPath = '$/acme/plugin/controllers/ControllerName/config_relation.yaml';

        $controller->relationConfig = $controller->mergeConfig(
            $controller->relationConfig,
            $myConfigPath
        );
    });

然后我将部分 _viewed_jobs.htm 更新为<?= $this->relationRender('viewedJobs') ?>

我现在将列表显示为 已完成列表添加到用户控制器的选项卡字段

于 2017-12-13T17:48:18.003 回答