Page 1 of 1

How to add more than one link to the Array in links-home.php?

Posted: 2020-10-24 08:24
by mohamed
Hello,

I need to add three (3) URLs in the Array in links-home.php :
../budget/Projects_2020.php
../budget/Projects_2021.php
../budget/Projects_2022.php

I am able to add a single link, but I don't How to add the other links!

I have tried to add the 2nd like for instance like this but it did not work:
'url' => '../budget/Projects_2020.php', '../budget/Projects_2021.php',

How to add more than one link to the Array ?



links-home.php
$homeLinks[] = array(
'url' => '../budget/Projects_2020.php',
'title' => 'Project of 2020',
'groups' => array('Users'),
);

Re: How to add more than one link to the Array in links-home.php?

Posted: 2020-10-24 08:59
by jsetzer

Code: Select all

// file: hooks/links-home.php

// #1
$homeLinks[] = array(
'url' => '../budget/Projects_2020.php',
'title' => 'Project of 2020',
'groups' => array('Users'),
);

// #2
$homeLinks[] = array(
'url' => '../budget/Projects_2021.php',
'title' => 'Project of 2021',
'groups' => array('Users'),
);

// ... repeat for every new home-link
$homeLinks[] = array(
'url' => '../budget/Projects_yyyy.php',
'title' => 'Project of yyyy',
'groups' => array('Users'),
);

Re: How to add more than one link to the Array in links-home.php?

Posted: 2020-10-24 09:04
by jsetzer
If you have named all custom pages after the same pattern:

Code: Select all

$min = 2020;
$max = 2022;
for ($y = $min; $y <= $max; $y++) {
  $homeLinks[] = array(
    'url' => "../budget/Projects_{$y}.php",
    'title' => 'Project of {$y}',
    'groups' => array('Users'),
    // more settings
  );
} // end for

Re: How to add more than one link to the Array in links-home.php?

Posted: 2020-10-24 09:09
by jsetzer
Instead of writing one script per year, you could also use the same script and pass the year as parameter:

Code: Select all

$min = 2020; // from starting year 2020...
$max = date("Y"); // until current year (including)

for ($y = $min; $y <= $max; $y++) {
  $homeLinks[] = array(
    'url' => "../budget/Projects_report.php?y={$y}",
    'title' => 'Projects of {$y}',
    'groups' => array('Users'),
    // more settings
  );
} // end for
In your report-script, fetch the year from URL:

Code: Select all

$y = isset($_REQUEST['y']) ? makeSafe($_REQUEST['y']) : date('Y');

Re: How to add more than one link to the Array in links-home.php?

Posted: 2020-10-24 10:05
by mohamed
Hello jsetzer,

Simply, you are a lifesaver ;)
and
many thanks for your generosity in sharing the code.


Have a nice day