Icingadb-web Header (addTitleTab)

Hello,

I want to create an icingadb-web module and I’m successful except for the header.

I’m trying to create a header like this:
Schermafbeelding 2024-05-05 204811

I thought that by placing
$this->addTitleTab(t('CSV Export'));
in the controller, it would create the header.

Does anyone know what else is needed to display the header on the screen?

The version of icinga/icingaweb/icingadb-web is the latest snapshot version

See here the code :

<?php

namespace Icinga\Module\export\Controllers;

use Icinga\Module\Icingadb\Web\Controller;
use ipl\Web\Url;
use ipl\Web\Compat\CompatController;
use Icinga\Application\Config;

class exportController extends Controller
{

   public function csvexportAction()
    {

           $this->addTitleTab(t('CSV Export'));

           $config = $this->Config();

... my code ....


    }

}

there is some problem with your namespace and controller name

for both you should use a capital E

also if you need more specific help please put in on github

Hello,

For security reasons, I had adjusted the name and forgot to consider the capital letters.

My module is working, but only the line of code addTitleTab is not functioning.
It doesn’t create the header.

What do you mean on GitHub? Should I open an issue in icingadb-web?
I don’t think this is a bug but rather that I don’t know how to do it because I’m not a PHP programmer.

If you put the full module on github I’m happy to help with that otherwise the effort is way to high to debug that in a forum post kind of way…

And considering it is most likely GPL infected code that is also the right way to do it…

1 Like

Hello @moreamazingnick

I’ve create my module and uploaded it to GitHub.

There’s a small description of the module and in the documentation section there are instructions on how to install/configure it.

The only thing I’d like to improve now is the header of my page.

I’d like to be able to set the title, with the refresh symbol next to it, and the close button on the right.
I thought this could be done for icingadb-web by placing the following line at the beginning of the code,

$this->addTitleTab(t(‘icingadb/hosts’));

but it does nothing at all.

Do you happen to know what I need to change in my code to display the title, refresh button, and close button on the screen?

you are mixing CompatController features with the in icingaweb2 previously more often used view part of the MVC-Pattern.

You can get rid of the whole columnexport.phtml (remove from disk) and use ipl code in your controller action:

use ipl\Html\Html;
$a = Html::tag('a',['href'=>"/path/",'name of the url']);
$div = Html::tag('div',['class'=>"test"]);
$div->add($a);
$this->addContent($div);

or your add the $tabs to your view file:

your columnexport.phtml

<div class="controls">
<h1><?= $this->headerpagetype ?></h1>
<h2>Format Export : <?= $this->headerexportformat ?></h2>
</div>

<div class="content">
  <?php foreach ($this->exportlinesarray as $index => $item): ?>
        <li><a href="<?= $item['exporturl'] ?>" target="_blank"><i  aria-hidden="true" class="<?= $item['exportclass'] ?>"></i><?= $item['exportname'] ?> (columns = <?= $item['exportcolumns'] ?>)<span class="info-box display-on-hover"> opens in new window </span></a></li>
  <?php endforeach ?>
</div>
<div class="controls">
    <?= $tabs; ?>
</div>

<div class="content">
    <h1><?= $this->headerpagetype ?></h1>
    <h2>Format Export : <?= $this->headerexportformat ?></h2>
  <?php foreach ($this->exportlinesarray as $index => $item): ?>
        <li><a href="<?= $item['exporturl'] ?>" target="_blank"><i  aria-hidden="true" class="<?= $item['exportclass'] ?>"></i><?= $item['exportname'] ?> (columns = <?= $item['exportcolumns'] ?>)<span class="info-box display-on-hover"> opens in new window </span></a></li>
  <?php endforeach ?>
</div>

This is what I was looking for!
Thank you!

I’ll now take a look at improving my script and wait for icinga to adjust my request for Export CSV/JSON to work with columns.

and this is very hard to debug if the code is incomplete.
let’s hit the solution button, and happy coding…