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

Reboot
Reboot

The documentation says that you can create new backend pages for a plugin via controller methods (actions) and a corresponding .htm page that matches the name of the controller action. That all works perfectly for me. The documentation also says you can pass variables to those pages via the controller behavior, but thats not working for me.

For example I created a sync method within my plugin's controller class and a sync.htm file. I added the section "sync" to the config_form.yaml and set the title to "sync", but the backend page is not picking up the title. Is there a way to pass data like that to custom backend pages using the controller behavior (config_form.yaml) or do you have to pass the data directly to the page via the controller action using the $this->vars property?

that0n3guy
that0n3guy

Are you talking about something like:

    public function update($recordId, $context = null)
    {
        // add datatables js and css
        $this->addJs('//cdn.datatables.net/1.10.0/js/jquery.dataTables.js');
        $this->addCss('//cdn.datatables.net/1.10.0/css/jquery.dataTables.css');

        // get header
        $helpers = new Helpers();
        $header = $helpers->getLastpostHeader($recordId);
        $this->vars['theader'] = $header;
        $this->vars['ocaform_id'] = $recordId;
        $this->vars['ordercolumn'] = array_search('created_at', $this->vars['theader']);
        $this->vars['tokens'] = $helpers->getPostdataTokens($helpers->getLastpostHeader($recordId, true), true);

        return $this->getClassExtension('Backend.Behaviors.FormController')->update($recordId, $context);
    }

The above is in my controller. Then in my update.htm I can use those variables like:

<div class="row">
    <div class="col-md-4">
        <h2>Tokens for Redirect URL & Emails</h2>
        <?= Datatable::table()
        ->addColumn('token','example data')       // these are the column headings to be shown
        ->setData($tokens)
        ->noScript()
        ->render();  ?>
    </div>
    <div class="col-md-8">
        <h2>Previously Submitted Forms. <small>Columns based on the fields in the last submitted form</small></h2>
        <?= Datatable::table()
        ->addColumn($theader)       // these are the column headings to be shown
        ->setOptions('order', array([$ordercolumn ,"desc"]))
        ->setUrl(route('that0n3guy.api.formposts', $ocaform_id))   // this is the route where data will be retrieved
        ->render() ?>
    </div>
</div>

You can see I use theader, ocaform_id, ordercolumn, tokens...

Last updated

Reboot
Reboot

Close, but instead of using the "update" method/action I would use a completely custom one called "sync" then have a corresponding sync.htm file for the view. Some of the variables I would use in the sync.htm file would be stored in the config_form.yaml file instead of being defined inside the controller method/action "sync".

Defining variables inside the controller's method/actions using the "$this->vars" property works fine, but I noticed some of the variables for the default "index", "create", "update" actions and corresponding .htm files are being passed through via the config_form.yaml file. For example the default create.htm page that gets created when you use the controller scaffolding command uses the variable/property $this->pageTitle that gets set by the title attribute under the create section of the config_form.yaml file.

that0n3guy
that0n3guy

I see, so you're asking how to pass them just from config yaml to view.... ?

Reboot
Reboot

Yep that's what I'm trying to accomplish.

that0n3guy
that0n3guy

I have no clue... I've not messed with this. Anyone else?

(try irc, someone there might be able to help)

1-6 of 6

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