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

pongan21326
pongan21326

I want to add a backend form field the blog posts that utilizes the Backend.Behaviors.RelationController. I created a new plugin and added this to the boot method.

public function boot()
{
        PostsController::extend(function($controller){
           $controller->implement[] = 'Backend.Behaviors.RelationController';
        });
}

I get the exception Class RainLab\Blog\Controllers\Posts must define property $relationConfig used by Backend\Behaviors\RelationController behavior. Which makes sense, but how do I dynamically define a property?

JeffGoldblum
JeffGoldblum

To dynamically define a property, just use it! :)


public function boot()
{
        PostsController::extend(function($controller){
           $controller->implement[] = 'Backend.Behaviors.RelationController';
           $controller->relationConfig = '$/myvendor/myplugin/controllers/posts/config_relation.yaml';
        });
}
pongan21326
pongan21326

Thanks, but that doesn't appear to work for me. To make sure everything else was right I tried adding:

public $relationConfig = '$/windmill/blog/controllers/posts/config_relation.yaml';

directly to the rainlab post controller and it works fine.

pongan21326
pongan21326

actually even if I just add

public $relationConfig;

to the post controller then it works.

tylko_sprawdzam
tylko_sprawdzam

In case anyone is still looking for a solution without editing the backend controller, you just have to extend it as below:

    \Backend\Controllers\Users::extend(function($controller){
        $controller->implement[] = 'Backend.Behaviors.RelationController';
        $controller->addDynamicProperty('relationConfig', '$/(...)/config_relation.yaml');
    });

Last updated

1-5 of 5

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