Simple recursive PHP function to build a HTML <ul> list from array

   
    /**
     * @param $array
     * @return string
     */
    function buildHtmlList($array)
    {
        $out = '<ul>';
        foreach($array as $key => $v) {
            if( is_array($v) ) {
                $out .= '<li>' . $key ;
                $out  .= buildHtmlList($v);
                $out .= '</li>';
                continue;
            } else {
                $out .= '<li>' . $array[$key] . '</li>';
            }
        }
        $out .= '</ul>';
        return $out;
    }
 
     $array = array(
         'Item 1' => array(
             'Sub Item 1' => array(
               'Sub Sub Item 1'
             ),
         ),
         'Item 2' => array(
             'Sub Item 2' => array(
                 'Sub Sub Item 2'
           ),
         ),
         'Item 3',
     );

     $result = buildHtmlList($array);

Result

  • Item 1
    • Sub Item 1
      • Sub Sub Item 1
  • Item 2
    • Sub Item 2
      • Sub Sub Item 2
  • Item 3

Or with class names

    
/**
 * @param array $array
 * @param array $classes
 * @param int $level
 * @return string
 */
function buildHtmlList($array,$classes='',$level=0)
{
    $out = '<ul>';
    if(!empty($classes)) {
        $out = '<ul'.$classes[$level].'>';
    }
    foreach($array as $key => $value) {
        if( is_array($value) ) {
            $i = $level+1;
            $out .= "<li>" . $key ;
            $out .= $this->buildHtmlList($value,$classes,$i);
            $out .= '</li>';
            continue;
        } else {
            $out .= "<li>" . $array[$key] . "</li>";
        }
    }
    $out .= "</ul>";
    return $out;
}
$arr = array(
    'Item 1' => array(
        'Sub Item 1' => array(
            'Sub Sub Item 1'
        ),
    ),
    'Item 2' => array(
        'Sub Item 2' => array(
            'Sub Sub Item 2'
        ),
    ),
    'Item 3',
);
$classes = array(
    ' class="level-1"',
    ' class="level-2"',
    ' class="level-3"'
);
$result = buildHtmlList($arr,$classes);

Result

<ul class="level-1">
    <li>Item 1
        <ul class="level-2">
            <li>Sub Item 1
                <ul class="level-3">
                    <li>Sub Sub Item 1</li>
                </ul>
            </li>
        </ul>
    </li>
    <li>Item 2
        <ul class="level-2">
            <li>Sub Item 2
                <ul class="level-3">
                    <li>Sub Sub Item 2</li>
                </ul>
            </li>
        </ul>
    </li>
    <li>Item 3</li>
</ul>

TYPO3 9.5 – Extbase Speaking URL’s

sites/xyz/config.yaml

routeEnhancers:
  Questionaire:
    type: Extbase
    limitToPages:
      - [PID DETAILS]
    extension: Questionaire
    plugin: Pi1
    routes:
      -
        routePath: '/{survey}'
_controller: 'Survey::show'
_arguments:
          survey_slug: survey
    requirements:
      survey_slug: '^[a-zA-Z0-9].*

aspects:
      survey_slug:
        type: PersistedAliasMapper
        tableName: tx_questionaire_domain_model_survey
        routeFieldName: slug

phpMyAdmin in Docker Container

Um das Image phpmyadmin/phpmyadmin fuer einen anderen Container zu nutzen, habe ich mir folgende docker-compose.yml angelegt:

version: '3'
services:
  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    environment:
      - PMA_ARBITRARY=1
    restart: always
    ports:
      - 8080:80
    volumes:
      - /sessions
    external_links:
      - ###CUSTOM_CONTAINER_1###
      - ###CUSTOM_CONTAINER_2###
    networks:
      - custom_network_1
      - custom_network_2
networks:
  custom_network_1:
    external:
      name: ###CUSTOM_CONTAINER_1_NETWORK###
  custom_network_2:
    external:
      name: ###CUSTOM_CONTAINER_2_NETWORK###