Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Laravel News:
Beautiful PHP CLI Menus for Laravel Artisan Commands
Feb 05, 2018 @ 16:33:53

On the Laravel News site today there's a post that highlights a package that makes it easier to create beautiful CLI menus for artisan commands in the Laravel framework.

Nuno Maduro, author of Laravel Zero and Collision (which nunomaduro/laravel-console-menu.

The post includes an example of code that can create the menu and its options. It also shows how you can change the look of the default menu, changing colors, the "selected" marker, padding and width. The package makes use of the php-school/cli-menu package for a lot of the base menu rendering and functionality.

tagged: tutorial menu cli artisan command laravel package

Link: https://laravel-news.com/beautiful-php-cli-menus-laravel-artisan-commands

Freek Van der Herten:
A modern package to generate html menus
Mar 25, 2016 @ 16:17:38

In this new post to his site Freek Van der Herten shares a new package he's worked up to help generate and maintain the status of menus in a Laravel application. While this example is Laravel-centric, there's also a framework-agnostic package that can be used in any application structure too.

Virtually every website displays some sort of menu. Generating html menus might seem simple, but it can become complex very quickly. Not only do you have to render some basic html, but you also have to manage which item is active. If a menu has a submenu you’ll also want the parents of an active item to be active. Sometimes you want to insert some html between menu items.

There are some packages out there that can help generating menus, but most of them have a messy API or have become victims of feature creep. Thanks why we decided to create our own modern menu package that has a beautiful API to work with.

He spends the rest of the post introducing the package, starting with the generation of a basic menu (and something a bit more complex). He also shows the use of the isActive method call to mark something as "active" but the package will handle that automatically for you if you'd like to keep it simple. He ends the post with a listing of the components that make this menu handling work (three of them) and some of the "modern PHP" functionality that they use.

tagged: menu package library html generate output manage active

Link: https://murze.be/2016/03/a-modern-package-to-generate-menus/

Symfony Finland:
What's on the Menu, Symfony?
Jan 28, 2016 @ 17:49:13

On the Symfony Finland site they've posted a tutorial about Symfony and menus, making use of the KnpMenuBundle to create flexible and easily configured menus with their own renderers.

Menus are a vital part of any web application or a website. Content Management Systems are traditionally a strong contender in this field as they are at their core just tools to create navigatable views to a pool of content. The Symfony Framework on the other hand is neutral when it comes to menus.

[...] There are a number of options for building menus in PHP, but the de-facto standard method for Symfony Framework is the KnpMenuBundle. It uses the KnpMenu library which is an object oriented PHP library for constructing and rendering menus.

The tutorial provides a simple example of using the bundle to create a menu with a handful of options and rendering it with a simple (included) ListRenderer. There's also an example of using a YAML configuration to create the menu and some example code of using a bit more complex and dynamic menu. They also talk a bit about content management systems, their use of menus and which they see as providing a better user experience than the others.

tagged: menu tutorial knpmenubundle symfony cms knplabs

Link: https://www.symfony.fi/entry/whats-on-the-menu-symfony

SitePoint PHP Blog:
How to Tidy Your WordPress Menu HTML
Jan 26, 2011 @ 15:37:59

On the SitePoint PHP blog today there's a new post from Craig Buckler for the WordPress users out there. The HTML that this popular blog/CMS tools spits out can sometimes be not-so-semantic. Craig shares a tip on cleaning up one aspect of it - the methods returning lists for menus or sitemaps.

love WordPress. I also love clean semantic HTML. Unfortunately, several of the standard WordPress theme functions return code that is a little untidy. For me, the primary culprits are wp_list_pages() and the newer wp_nav_menu(); both return an unordered list of page links.

He gives an example of a sample list generated by wp_nav_menu() that's full of badly formatted and unnecessary elements. To help fix the issue, he shares his regular expression-based call to strip out things like extra tabs, empty classes and all title attributes. Obviously you can customize this as you need, but it's a good start towards something that's a bit cleaner and up to code.

tagged: wordpress tidy html output pregreplace regularexpression menu

Link:

PHPro.org:
Dynamically Create Menu With PHP DOM
Jul 20, 2009 @ 15:50:52

New from Kevin Waterson on the PHPro.org site is this tutorial looking at dynamically making a website menu with PHP's DOM functionality.

Most PHP coders will have their own menu generation class that will take an array or an item and add it to a HTML un-ordered list or other tag and the styling is handled with CSS. This has proven to be a worthy solution to menu creation, however, PHP already has all the tools and classes built in to create a menu using DOM. It is both powerful and extensible and further eliminates for yet another class in your tree.

The tutorial shows you how to create a simple XML document to define the menu using the DOM functionality in PHP and finally output it as a series of unordered lists that can be styled in whatever way you want.

tagged: xml dom menu dynamic

Link:

Tiffany Brown's Blog:
Turn text files into pull down menus
Feb 27, 2008 @ 15:35:00

Tiffany Brown shares a quick function she whipped up to create dropdown menus from the contents of a newline separated text file (or files).

I developed this PHP function for a project I'm working on. I'm posting it here in case I need it again, or in case you find it handy.

The function turns each line into an option tag making defining custom menus based on the contents of dynamically-given text files easy.

This could also be easily adapted to create navigations menus at the top of your pages with a few modifications to the HTML tags being used and some CSS to change the look of the list.

tagged: text file dropdown menu form element navigation css

Link:

Arnold Daniels' Blog:
How I PHP: The Output Handler - Continued
Dec 07, 2007 @ 15:32:00

Continuing on from his previous post on output handling, Arnold Daniels shows how to build on the previous setup and add the ability to include dynamic data into the template.

For instance, it would be nice if the data in the left column, 'Beauty Tips', could be different for each page. There are several ways to solve this, but for know I will choose the simplest.

He takes a few steps to make adding the content simple:

  • Adding markers for the title and left menu to the template
  • Change the OutputHandler class to make it less static
  • use setData() to title the page
  • user setData() to add left column content
  • Use mark() and endmark() to section off a part of the template.

He's provided a demo and made the source code available for download.

tagged: output handler dynamic content title menu output handler dynamic content title menu

Link:

Arnold Daniels' Blog:
How I PHP: The Output Handler - Continued
Dec 07, 2007 @ 15:32:00

Continuing on from his previous post on output handling, Arnold Daniels shows how to build on the previous setup and add the ability to include dynamic data into the template.

For instance, it would be nice if the data in the left column, 'Beauty Tips', could be different for each page. There are several ways to solve this, but for know I will choose the simplest.

He takes a few steps to make adding the content simple:

  • Adding markers for the title and left menu to the template
  • Change the OutputHandler class to make it less static
  • use setData() to title the page
  • user setData() to add left column content
  • Use mark() and endmark() to section off a part of the template.

He's provided a demo and made the source code available for download.

tagged: output handler dynamic content title menu output handler dynamic content title menu

Link:

Felix Geisendorfer's Blog:
MacGyver menu for CakePHP - What's the active menu item?
Jul 09, 2007 @ 14:34:00

In a new post to his blog today, Felix Geisendorfer talks about view coding - specifically working with a menu and determining which element is active.

One of the challenges many of us have faced before and will face in future is building a menu. Now this of course is very simple assuming that we're just shooting for a static <ul> with some <li>'s containing the links. However the tricky part is to figure out what is the active menu item. I had some code doing this in the past but tried out a new flavor of it today which I call the MacGyver menu for CakePHP as it's a little dirty yet powerful and easy to maintain.

In his included code, he creates a simple navigation from an array of titles/links and, with some sorting, a regular expression and a CSS class, the selected item can be highlighted simply.

tagged: cakephp framework navigation highlight active menu cakephp framework navigation highlight active menu

Link:

Felix Geisendorfer's Blog:
MacGyver menu for CakePHP - What's the active menu item?
Jul 09, 2007 @ 14:34:00

In a new post to his blog today, Felix Geisendorfer talks about view coding - specifically working with a menu and determining which element is active.

One of the challenges many of us have faced before and will face in future is building a menu. Now this of course is very simple assuming that we're just shooting for a static <ul> with some <li>'s containing the links. However the tricky part is to figure out what is the active menu item. I had some code doing this in the past but tried out a new flavor of it today which I call the MacGyver menu for CakePHP as it's a little dirty yet powerful and easy to maintain.

In his included code, he creates a simple navigation from an array of titles/links and, with some sorting, a regular expression and a CSS class, the selected item can be highlighted simply.

tagged: cakephp framework navigation highlight active menu cakephp framework navigation highlight active menu

Link:


Trending Topics: